adventofcode/2020/day25/main.go

48 lines
823 B
Go

package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func init() {
}
func main() {
fmt.Println("# Day 25")
inp := h.StdinToStringSlice()
solve(inp, h.Atoi(h.OptArgNumber(1, "2")))
}
func solve(inp []string, part int) {
card, door := 7, 7
cardPub := h.Atoi(inp[0])
doorPub := h.Atoi(inp[1])
var cardLoops, doorLoops int
cardVal, doorVal := 1, 1
for cardVal != cardPub {
cardVal = loop(cardVal, card)
cardLoops++
}
for doorVal != doorPub {
doorVal = loop(doorVal, door)
doorLoops++
}
fmt.Println("Card Loop Size:", cardLoops)
fmt.Println("Door Loop Size:", doorLoops)
ans := 1
for i := 0; i < cardLoops; i++ {
ans = loop(ans, doorVal)
}
fmt.Println("Answer:", ans)
}
const div = 20201227
func loop(v, subject int) int {
v = v * subject
return v % div
}