day4
This commit is contained in:
@@ -19,9 +19,20 @@ func ToInts(input string, sep string) []int {
|
||||
}
|
||||
|
||||
func ToGrid2D[T any](input, rowSep, colSep string, empty T, conv func(string) T) *grid2d.Grid[T] {
|
||||
lines := strings.Split(input, rowSep)
|
||||
|
||||
grid := grid2d.NewGrid(len(lines[0]) - strings.Count(lines[0], colSep), len(lines), empty)
|
||||
var width int
|
||||
|
||||
lines := strings.Split(input, rowSep)
|
||||
|
||||
if colSep == "" {
|
||||
// If no colSep, width is the length of each line
|
||||
width = len(lines[0])
|
||||
} else {
|
||||
// Use colSep to determine the width of the grid
|
||||
width = len(strings.Split(lines[0], colSep))
|
||||
}
|
||||
|
||||
grid := grid2d.NewGrid(width, len(lines), empty)
|
||||
for y, line := range lines {
|
||||
for x, v := range strings.Split(line, colSep) {
|
||||
grid.Set(x, y, conv(v))
|
||||
|
||||
Reference in New Issue
Block a user