adventofcode/2020/day25.go
2020-12-25 21:33:52 +00:00

52 lines
820 B
Go

package main
import (
"fmt"
"os"
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
)
func findLoopSize(pubKey, subject int) int {
value := 1
for i := 0; ; i++ {
value *= subject
value %= 20201227
if value == pubKey {
return i + 1
}
}
}
func transformLoop(pubKey, loopSize int) int {
value := 1
for i := 0; i < loopSize; i++ {
value *= pubKey
value %= 20201227
}
return value
}
func main() {
step := os.Args[1]
values := util.InputParserInts(os.Args[2])
keyPub := values[0]
doorPub := values[1]
keyLoop := findLoopSize(keyPub, 7)
doorLoop := findLoopSize(doorPub, 7)
encryptionKey1 := transformLoop(keyPub, doorLoop)
encryptionKey2 := transformLoop(doorPub, keyLoop)
switch step {
case "1":
fmt.Println(encryptionKey1)
fmt.Println(encryptionKey2)
case "2":
}
}