Day 25 solved.
This commit is contained in:
parent
ed95f875ad
commit
c604a4074f
51
2020/day25.go
Normal file
51
2020/day25.go
Normal file
|
@ -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":
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user