day21: yuck
This commit is contained in:
parent
6a7378c265
commit
f5ea9e725e
|
@ -9,3 +9,12 @@ but i could be doing loop around that would increase path len by odd number
|
||||||
|
|
||||||
let's just make direct recursive thing.
|
let's just make direct recursive thing.
|
||||||
create set of all reachable by n,
|
create set of all reachable by n,
|
||||||
|
* oh, the part 2.
|
||||||
|
i suppose this 'infinite' garden could be managed with my 'neighbors' work with 'out of field'
|
||||||
|
fairly easy
|
||||||
|
but what about sizes of the maps? are we releasing maps of previous iterations?
|
||||||
|
|
||||||
|
maybe if i directly pass references to prev and current,
|
||||||
|
and manually set 'prev' to target new it will be collected?
|
||||||
|
|
||||||
|
and then elements after these steps <em>26501365</em> would fit into memory?
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
func Run() int {
|
func Run() int {
|
||||||
fmt.Print("hello day21")
|
fmt.Print("hello day21")
|
||||||
filename := "day21/input"
|
filename := "day21/example"
|
||||||
field := ReadField(filename)
|
field := ReadField(filename)
|
||||||
log.Print(field)
|
log.Print(field)
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ func Run() int {
|
||||||
|
|
||||||
fmt.Println(field.PrintCoord(reachableBySixtyFour))
|
fmt.Println(field.PrintCoord(reachableBySixtyFour))
|
||||||
|
|
||||||
|
|
||||||
return len(reachableBySixtyFour)
|
return len(reachableBySixtyFour)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +36,7 @@ type Coord struct {
|
||||||
Row, Col int
|
Row, Col int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f Field) ReachableBySteps(n int, startingAt map[Coord]any) map[Coord]any {
|
||||||
func (f Field)ReachableBySteps(n int, startingAt map[Coord]any) map[Coord]any {
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return startingAt
|
return startingAt
|
||||||
}
|
}
|
||||||
|
@ -54,7 +52,6 @@ func (f Field)ReachableBySteps(n int, startingAt map[Coord]any) map[Coord]any {
|
||||||
return f.ReachableBySteps(n-1, oneStepExpanded)
|
return f.ReachableBySteps(n-1, oneStepExpanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (f Field) Neighbors(c Coord) (resut []Coord) {
|
func (f Field) Neighbors(c Coord) (resut []Coord) {
|
||||||
closeCoords := []Coord{
|
closeCoords := []Coord{
|
||||||
{Row: c.Row + 1, Col: c.Col},
|
{Row: c.Row + 1, Col: c.Col},
|
||||||
|
@ -64,11 +61,13 @@ func (f Field) Neighbors(c Coord) (resut []Coord) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, close := range closeCoords {
|
for _, close := range closeCoords {
|
||||||
|
if f.ValidCoord(close.Row, close.Col) {
|
||||||
symb := f.symbols[close.Row][close.Col]
|
symb := f.symbols[close.Row][close.Col]
|
||||||
validNextPlace := f.ValidCoord(close.Row, close.Col) &&
|
if symb == '.' || symb == 'S' {
|
||||||
(symb == '.' || symb == 'S')
|
|
||||||
if validNextPlace {
|
|
||||||
resut = append(resut, close)
|
resut = append(resut, close)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +113,7 @@ func ReadField(filename string) (result Field) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Field)PrintCoord(coords map[Coord]any) string {
|
func (f Field) PrintCoord(coords map[Coord]any) string {
|
||||||
result := ""
|
result := ""
|
||||||
for rowNum, row := range f.symbols {
|
for rowNum, row := range f.symbols {
|
||||||
for colNum, col := range row {
|
for colNum, col := range row {
|
||||||
|
|
Loading…
Reference in New Issue