From f5ea9e725e19007dd70a894dac0f88431e3a5be0 Mon Sep 17 00:00:00 2001 From: efim Date: Thu, 21 Dec 2023 08:39:27 +0000 Subject: [PATCH] day21: yuck --- day21/notes.org | 9 +++++++++ day21/stepCounter.go | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/day21/notes.org b/day21/notes.org index 0048cc7..c507e83 100644 --- a/day21/notes.org +++ b/day21/notes.org @@ -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. 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 26501365 would fit into memory? diff --git a/day21/stepCounter.go b/day21/stepCounter.go index 539412d..af48cb1 100644 --- a/day21/stepCounter.go +++ b/day21/stepCounter.go @@ -9,7 +9,7 @@ import ( func Run() int { fmt.Print("hello day21") - filename := "day21/input" + filename := "day21/example" field := ReadField(filename) log.Print(field) @@ -19,7 +19,6 @@ func Run() int { fmt.Println(field.PrintCoord(reachableBySixtyFour)) - return len(reachableBySixtyFour) } @@ -37,8 +36,7 @@ type Coord struct { 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 { 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) } - func (f Field) Neighbors(c Coord) (resut []Coord) { closeCoords := []Coord{ {Row: c.Row + 1, Col: c.Col}, @@ -64,11 +61,13 @@ func (f Field) Neighbors(c Coord) (resut []Coord) { } for _, close := range closeCoords { - symb := f.symbols[close.Row][close.Col] - validNextPlace := f.ValidCoord(close.Row, close.Col) && - (symb == '.' || symb == 'S') - if validNextPlace { - resut = append(resut, close) + if f.ValidCoord(close.Row, close.Col) { + symb := f.symbols[close.Row][close.Col] + if symb == '.' || symb == 'S' { + resut = append(resut, close) + + } + } } @@ -114,7 +113,7 @@ func ReadField(filename string) (result Field) { return } -func (f Field)PrintCoord(coords map[Coord]any) string { +func (f Field) PrintCoord(coords map[Coord]any) string { result := "" for rowNum, row := range f.symbols { for colNum, col := range row {