39 lines
580 B
Go
39 lines
580 B
Go
|
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)
|
||
|
}
|