From e541631a35aee728a7d9029df7583190c28307f9 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 22 Dec 2023 22:03:12 +0000 Subject: [PATCH] rename var move in runner() uncomment debug logs --- day-16/one.go | 106 +++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 54 deletions(-) diff --git a/day-16/one.go b/day-16/one.go index 36a3491..3f2f7eb 100644 --- a/day-16/one.go +++ b/day-16/one.go @@ -25,84 +25,82 @@ const ( var steps int var dirs = []string{"N", "S", "W", "E"} -func runner(move *mover, lines []string) { - for steps < math.MaxInt && move.Y >= 0 && move.Y < len(lines) && move.X >= 0 && move.X < len(lines[move.Y]) { - //log.Debug(move.X, ":", move.Y, " ", string(lines[move.Y][move.X]), " ", dirs[move.direction()]) - //log.Debug(move.nodes) - if nodeInNodes(move.node, move.nodes) { - log.Debug(move.node, " in nodes, breaking.") +func runner(mover *mover, lines []string) { + for steps < math.MaxInt && mover.Y >= 0 && mover.Y < len(lines) && mover.X >= 0 && mover.X < len(lines[mover.Y]) { + if nodeInNodes(mover.node, mover.nodes) { + log.Debug(mover.node, " in nodes, breaking.") break } - move.nodes = append(move.nodes, move.node) + mover.nodes = append(mover.nodes, mover.node) - switch lines[move.Y][move.X] { + switch lines[mover.Y][mover.X] { case SPACE: // '.' - //log.Debug("we have space and direction is ", dirs[move.direction()]) - move.move() + log.Debug("we have space and direction is ", dirs[mover.direction()]) + mover.move() case F_MIRROR: // '/' - //log.Debug("we have forward mirror and direction is ", dirs[move.direction()]) - switch move.direction() { + log.Debug("we have forward mirror and direction is ", dirs[mover.direction()]) + switch mover.direction() { case N: - move.setDirection(E) + mover.setDirection(E) case S: - move.setDirection(W) + mover.setDirection(W) case W: - move.setDirection(S) + mover.setDirection(S) case E: - move.setDirection(N) + mover.setDirection(N) } - //log.Debug("step: ", steps, " ", string(F_MIRROR), " direction changed to ", dirs[move.direction()]) - move.move() + log.Debug("step: ", steps, " ", string(F_MIRROR), " direction changed to ", dirs[mover.direction()]) + mover.move() case B_MIRROR: // '\' - //log.Debug("we have backwards mirror and direction is ", dirs[move.direction()]) - switch move.direction() { + log.Debug("we have backwards mirror and direction is ", dirs[mover.direction()]) + switch mover.direction() { case N: - move.setDirection(W) + mover.setDirection(W) case S: - move.setDirection(E) + mover.setDirection(E) case W: - move.setDirection(N) + mover.setDirection(N) case E: - move.setDirection(S) + mover.setDirection(S) } - //log.Debug("step: ", steps, " ", string(B_MIRROR), " direction changed to ", dirs[move.direction()]) - move.move() + log.Debug("step: ", steps, " ", string(B_MIRROR), " direction changed to ", dirs[mover.direction()]) + mover.move() case V_MIRROR: // '|' - //log.Debug("we have vertical mirror and direction is ", dirs[move.direction()]) - if move.direction() == N || move.direction() == S { - move.move() + log.Debug("we have vertical mirror and direction is ", dirs[mover.direction()]) + if mover.direction() == N || mover.direction() == S { + mover.move() continue } - if move.direction() == W || move.direction() == E { - c := move.coords - move.setDirection(N) - move.move() - runner(move, lines) - move.coords = c - move.setDirection(S) - move.move() - runner(move, lines) + if mover.direction() == W || mover.direction() == E { + c := mover.coords + mover.setDirection(N) + mover.move() + runner(mover, lines) + mover.coords = c + mover.setDirection(S) + mover.move() + runner(mover, lines) } case H_MIRROR: // '-' - //log.Debug("we have horizontal mirror and direction is ", dirs[move.direction()]) - if move.direction() == W || move.direction() == E { - move.move() + log.Debug("we have horizontal mirror and direction is ", dirs[mover.direction()]) + if mover.direction() == W || mover.direction() == E { + mover.move() continue } - if move.direction() == N || move.direction() == S { - c := move.coords - move.setDirection(W) - move.move() - runner(move, lines) - move.coords = c - move.setDirection(E) - move.move() - runner(move, lines) + if mover.direction() == N || mover.direction() == S { + c := mover.coords + mover.setDirection(W) + mover.move() + runner(mover, lines) + mover.coords = c + mover.setDirection(E) + mover.move() + runner(mover, lines) } default: @@ -114,14 +112,14 @@ func runner(move *mover, lines []string) { // one func one(lines []string) int { - move := newMover(newNode(0, 0, E)) + mover := newMover(newNode(0, 0, E)) - runner(move, lines) + runner(mover, lines) if log.GetLevel() == log.DebugLevel { - n := printDebug(move, lines) + n := printDebug(mover, lines) log.Debug("total: ", n) } - return uniqueNodes(move) + return uniqueNodes(mover) }