mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 23:20:49 +00:00
29 lines
440 B
Go
29 lines
440 B
Go
|
package main
|
||
|
|
||
|
const (
|
||
|
LEFT = iota // 0
|
||
|
RIGHT
|
||
|
)
|
||
|
|
||
|
var directions string
|
||
|
var steps = map[string][]string{}
|
||
|
|
||
|
// one returns the number of steps to reach 'ZZZ'
|
||
|
func one(lines []string) int {
|
||
|
parselines(lines)
|
||
|
|
||
|
num := 0
|
||
|
for i, step := 0, "AAA"; step != "ZZZ"; i, num = i+1, num+1 {
|
||
|
if i == len(directions) {
|
||
|
i = 0
|
||
|
}
|
||
|
if directions[i] == 'L' {
|
||
|
step = steps[step][LEFT]
|
||
|
} else {
|
||
|
step = steps[step][RIGHT]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return num
|
||
|
}
|