mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-22 10:20:48 +00:00
rename var move in runner()
uncomment debug logs
This commit is contained in:
parent
038dd531d9
commit
e541631a35
106
day-16/one.go
106
day-16/one.go
@ -25,84 +25,82 @@ const (
|
|||||||
var steps int
|
var steps int
|
||||||
var dirs = []string{"N", "S", "W", "E"}
|
var dirs = []string{"N", "S", "W", "E"}
|
||||||
|
|
||||||
func runner(move *mover, lines []string) {
|
func runner(mover *mover, lines []string) {
|
||||||
for steps < math.MaxInt && move.Y >= 0 && move.Y < len(lines) && move.X >= 0 && move.X < len(lines[move.Y]) {
|
for steps < math.MaxInt && mover.Y >= 0 && mover.Y < len(lines) && mover.X >= 0 && mover.X < len(lines[mover.Y]) {
|
||||||
//log.Debug(move.X, ":", move.Y, " ", string(lines[move.Y][move.X]), " ", dirs[move.direction()])
|
if nodeInNodes(mover.node, mover.nodes) {
|
||||||
//log.Debug(move.nodes)
|
log.Debug(mover.node, " in nodes, breaking.")
|
||||||
if nodeInNodes(move.node, move.nodes) {
|
|
||||||
log.Debug(move.node, " in nodes, breaking.")
|
|
||||||
break
|
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: // '.'
|
case SPACE: // '.'
|
||||||
//log.Debug("we have space and direction is ", dirs[move.direction()])
|
log.Debug("we have space and direction is ", dirs[mover.direction()])
|
||||||
move.move()
|
mover.move()
|
||||||
|
|
||||||
case F_MIRROR: // '/'
|
case F_MIRROR: // '/'
|
||||||
//log.Debug("we have forward mirror and direction is ", dirs[move.direction()])
|
log.Debug("we have forward mirror and direction is ", dirs[mover.direction()])
|
||||||
switch move.direction() {
|
switch mover.direction() {
|
||||||
case N:
|
case N:
|
||||||
move.setDirection(E)
|
mover.setDirection(E)
|
||||||
case S:
|
case S:
|
||||||
move.setDirection(W)
|
mover.setDirection(W)
|
||||||
case W:
|
case W:
|
||||||
move.setDirection(S)
|
mover.setDirection(S)
|
||||||
case E:
|
case E:
|
||||||
move.setDirection(N)
|
mover.setDirection(N)
|
||||||
}
|
}
|
||||||
//log.Debug("step: ", steps, " ", string(F_MIRROR), " direction changed to ", dirs[move.direction()])
|
log.Debug("step: ", steps, " ", string(F_MIRROR), " direction changed to ", dirs[mover.direction()])
|
||||||
move.move()
|
mover.move()
|
||||||
|
|
||||||
case B_MIRROR: // '\'
|
case B_MIRROR: // '\'
|
||||||
//log.Debug("we have backwards mirror and direction is ", dirs[move.direction()])
|
log.Debug("we have backwards mirror and direction is ", dirs[mover.direction()])
|
||||||
switch move.direction() {
|
switch mover.direction() {
|
||||||
case N:
|
case N:
|
||||||
move.setDirection(W)
|
mover.setDirection(W)
|
||||||
case S:
|
case S:
|
||||||
move.setDirection(E)
|
mover.setDirection(E)
|
||||||
case W:
|
case W:
|
||||||
move.setDirection(N)
|
mover.setDirection(N)
|
||||||
case E:
|
case E:
|
||||||
move.setDirection(S)
|
mover.setDirection(S)
|
||||||
}
|
}
|
||||||
//log.Debug("step: ", steps, " ", string(B_MIRROR), " direction changed to ", dirs[move.direction()])
|
log.Debug("step: ", steps, " ", string(B_MIRROR), " direction changed to ", dirs[mover.direction()])
|
||||||
move.move()
|
mover.move()
|
||||||
|
|
||||||
case V_MIRROR: // '|'
|
case V_MIRROR: // '|'
|
||||||
//log.Debug("we have vertical mirror and direction is ", dirs[move.direction()])
|
log.Debug("we have vertical mirror and direction is ", dirs[mover.direction()])
|
||||||
if move.direction() == N || move.direction() == S {
|
if mover.direction() == N || mover.direction() == S {
|
||||||
move.move()
|
mover.move()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if move.direction() == W || move.direction() == E {
|
if mover.direction() == W || mover.direction() == E {
|
||||||
c := move.coords
|
c := mover.coords
|
||||||
move.setDirection(N)
|
mover.setDirection(N)
|
||||||
move.move()
|
mover.move()
|
||||||
runner(move, lines)
|
runner(mover, lines)
|
||||||
move.coords = c
|
mover.coords = c
|
||||||
move.setDirection(S)
|
mover.setDirection(S)
|
||||||
move.move()
|
mover.move()
|
||||||
runner(move, lines)
|
runner(mover, lines)
|
||||||
}
|
}
|
||||||
|
|
||||||
case H_MIRROR: // '-'
|
case H_MIRROR: // '-'
|
||||||
//log.Debug("we have horizontal mirror and direction is ", dirs[move.direction()])
|
log.Debug("we have horizontal mirror and direction is ", dirs[mover.direction()])
|
||||||
if move.direction() == W || move.direction() == E {
|
if mover.direction() == W || mover.direction() == E {
|
||||||
move.move()
|
mover.move()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if move.direction() == N || move.direction() == S {
|
if mover.direction() == N || mover.direction() == S {
|
||||||
c := move.coords
|
c := mover.coords
|
||||||
move.setDirection(W)
|
mover.setDirection(W)
|
||||||
move.move()
|
mover.move()
|
||||||
runner(move, lines)
|
runner(mover, lines)
|
||||||
move.coords = c
|
mover.coords = c
|
||||||
move.setDirection(E)
|
mover.setDirection(E)
|
||||||
move.move()
|
mover.move()
|
||||||
runner(move, lines)
|
runner(mover, lines)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -114,14 +112,14 @@ func runner(move *mover, lines []string) {
|
|||||||
|
|
||||||
// one
|
// one
|
||||||
func one(lines []string) int {
|
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 {
|
if log.GetLevel() == log.DebugLevel {
|
||||||
n := printDebug(move, lines)
|
n := printDebug(mover, lines)
|
||||||
log.Debug("total: ", n)
|
log.Debug("total: ", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
return uniqueNodes(move)
|
return uniqueNodes(mover)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user