day16: part 2

This commit is contained in:
efim 2023-12-16 07:34:26 +00:00
parent ee9c2c1ca0
commit ed4abd2d7e

View File

@ -12,7 +12,7 @@ import (
func Run() int { func Run() int {
fmt.Println("hello from day 16") fmt.Println("hello from day 16")
log.Println("starting") log.Println("starting")
filename := "day16/example" filename := "day16/input"
field := ReadField(filename) field := ReadField(filename)
startPoints := StartPoints(&field) startPoints := StartPoints(&field)
@ -194,7 +194,7 @@ func (f *Field) CountEnergized() (result int) {
func (f *Field) RecordVisits(reportedPoints <-chan MovementPoint) { func (f *Field) RecordVisits(reportedPoints <-chan MovementPoint) {
for point := range reportedPoints { for point := range reportedPoints {
cell := f.cells[point.Row][point.Col] cell := f.cells[point.Row][point.Col]
log.Printf("recording visit %+v to %+v at row %d col %d\n", point, cell, point.Row, point.Col) // log.Printf("recording visit %+v to %+v at row %d col %d\n", point, cell, point.Row, point.Col)
cell.KnownBeams[point.Direction] = struct{}{} cell.KnownBeams[point.Direction] = struct{}{}
} }
} }
@ -203,7 +203,7 @@ func (f *Field) RecordVisits(reportedPoints <-chan MovementPoint) {
// move (concurrently if required) into next points // move (concurrently if required) into next points
// ends - when out of the field, or if encountering a cycle // ends - when out of the field, or if encountering a cycle
func (f *Field) TraverseFrom(current MovementPoint, reportVisits chan<- MovementPoint, wg *sync.WaitGroup) { func (f *Field) TraverseFrom(current MovementPoint, reportVisits chan<- MovementPoint, wg *sync.WaitGroup) {
log.Printf("> starting traverse through %+v", current) // log.Printf("> starting traverse through %+v", current)
if !f.isValid(current) { if !f.isValid(current) {
log.Println("invalid current ", current, " should be impossible") log.Println("invalid current ", current, " should be impossible")
wg.Done() wg.Done()
@ -212,7 +212,7 @@ func (f *Field) TraverseFrom(current MovementPoint, reportVisits chan<- Movement
cell := f.cells[current.Row][current.Col] cell := f.cells[current.Row][current.Col]
_, knownDirection := cell.KnownBeams[current.Direction] _, knownDirection := cell.KnownBeams[current.Direction]
if knownDirection { if knownDirection {
log.Printf("found cycle at %+v in %+v", current, cell) // log.Printf("found cycle at %+v in %+v", current, cell)
wg.Done() wg.Done()
return return
} }
@ -220,7 +220,7 @@ func (f *Field) TraverseFrom(current MovementPoint, reportVisits chan<- Movement
reportVisits <- current reportVisits <- current
nextPoints := NextPoints(f, current) nextPoints := NextPoints(f, current)
log.Printf("for current %+v next are: %+v\n", current, nextPoints) // log.Printf("for current %+v next are: %+v\n", current, nextPoints)
switch len(nextPoints) { switch len(nextPoints) {
case 0: case 0:
wg.Done() wg.Done()