Browse Source

Advent of Code 2020 is Complete!

master
Brian Buller 9 months ago
parent
commit
49a625c6e6
  1. 2
      2020/day23/main.go
  2. 2
      2020/day24/main.go
  3. 2
      2020/day25/input
  4. 47
      2020/day25/main.go
  5. 2
      2020/day25/testinput

2
2020/day23/main.go

@ -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")))

2
2020/day24/main.go

@ -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

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

47
2020/day25/main.go

@ -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

@ -0,0 +1,2 @@
5764801
17807724
Loading…
Cancel
Save