mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-07 12:45:10 +02:00
add halp package for printing infinite grids, which seems to be quite common. generics may be useful here oneday...
This commit is contained in:
+3
-24
@@ -95,7 +95,8 @@ func enhanceImg(img map[[2]int]string, alg []string, infiniteSpaceStaysOff, infi
|
||||
}
|
||||
|
||||
// fmt.Println("BEFORE")
|
||||
// fmt.Println(imgString(img))
|
||||
// debugging helper to print an infinite grid for
|
||||
// halp.PrintInfiniteGridStrings(img, ".")
|
||||
|
||||
// now only need to check within firstRow - 2 through lastRow + 2 (same for cols)
|
||||
// because flickers will kill that third row/col out
|
||||
@@ -109,7 +110,7 @@ func enhanceImg(img map[[2]int]string, alg []string, infiniteSpaceStaysOff, infi
|
||||
}
|
||||
|
||||
// fmt.Println("AFTER")
|
||||
// fmt.Println(imgString(next))
|
||||
// halp.PrintInfiniteGridStrings(next, ".")
|
||||
|
||||
return next
|
||||
}
|
||||
@@ -155,25 +156,3 @@ func parseInput(input string) (alg []string, img map[[2]int]string) {
|
||||
|
||||
return alg, img
|
||||
}
|
||||
|
||||
// printing for debugging
|
||||
// TODO pull into algos package for easier debugging. make a printing package?
|
||||
func imgString(img map[[2]int]string) string {
|
||||
// get bounds
|
||||
var firstRow, lastRow, firstCol, lastCol int
|
||||
for coord := range img {
|
||||
firstRow = mathy.MinInt(firstRow, coord[0])
|
||||
lastRow = mathy.MaxInt(lastRow, coord[0])
|
||||
firstCol = mathy.MinInt(firstCol, coord[1])
|
||||
lastCol = mathy.MaxInt(lastCol, coord[1])
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
for r := firstRow; r <= lastRow; r++ {
|
||||
for c := firstCol; c <= lastCol; c++ {
|
||||
sb.WriteString(img[[2]int{r, c}])
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user