Day 15 solution.
This commit is contained in:
parent
2614bb2def
commit
0ba29a4e75
38
2020/day15.go
Normal file
38
2020/day15.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user