Day 15 solution.

This commit is contained in:
Anna Rose 2020-12-15 05:25:21 +00:00
parent 2614bb2def
commit 0ba29a4e75

38
2020/day15.go Normal file
View File

@ -0,0 +1,38 @@
package main
import (
"fmt"
"os"
)
func main() {
step := os.Args[1]
indexMap := make(map[int]int)
indexMap[0] = 0
indexMap[14] = 1
indexMap[1] = 2
indexMap[3] = 3
indexMap[7] = 4
last := 9
loops := 0
switch step {
case "1":
loops = 2020
case "2":
loops = 30000000
}
for i := 5; i < loops-1; i++ {
if x, ok := indexMap[last]; ok {
indexMap[last] = i
// fmt.Printf("%d was last seen %d ago\n", last, i-x)
last = i - x
} else {
indexMap[last] = i
// fmt.Printf("%d has not been seen before\n", last)
last = 0
}
}
fmt.Println(last)
}