Advent of Code 2020 is Complete!

This commit is contained in:
Brian Buller 2020-12-25 07:57:34 -06:00
parent 10a3ba0699
commit 49a625c6e6
5 changed files with 53 additions and 2 deletions

View File

@ -17,7 +17,7 @@ func init() {
}
func main() {
fmt.Println("# Day 22")
fmt.Println("# Day 23")
inp := h.StdinToString()
solve(inp, h.Atoi(h.OptArgNumber(1, "2")))

View File

@ -18,7 +18,7 @@ func init() {
}
func main() {
fmt.Println("# Day 22")
fmt.Println("# Day 24")
inp := h.StdinToStringSlice()
solve(inp, h.Atoi(h.OptArgNumber(1, "2")))

2
2020/day25/input Normal file
View File

@ -0,0 +1,2 @@
3248366
4738476

47
2020/day25/main.go Normal file
View File

@ -0,0 +1,47 @@
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
}

2
2020/day25/testinput Normal file
View File

@ -0,0 +1,2 @@
5764801
17807724