From c604a4074faa837999f1a4454925e3e3c310b8db Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 25 Dec 2020 21:33:52 +0000 Subject: [PATCH] Day 25 solved. --- 2020/day25.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 2020/day25.go diff --git a/2020/day25.go b/2020/day25.go new file mode 100644 index 0000000..f712e75 --- /dev/null +++ b/2020/day25.go @@ -0,0 +1,51 @@ +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": + } +}