Advent of Code 2020 is Complete!
This commit is contained in:
parent
10a3ba0699
commit
49a625c6e6
@ -17,7 +17,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("# Day 22")
|
fmt.Println("# Day 23")
|
||||||
inp := h.StdinToString()
|
inp := h.StdinToString()
|
||||||
|
|
||||||
solve(inp, h.Atoi(h.OptArgNumber(1, "2")))
|
solve(inp, h.Atoi(h.OptArgNumber(1, "2")))
|
||||||
|
@ -18,7 +18,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("# Day 22")
|
fmt.Println("# Day 24")
|
||||||
inp := h.StdinToStringSlice()
|
inp := h.StdinToStringSlice()
|
||||||
|
|
||||||
solve(inp, h.Atoi(h.OptArgNumber(1, "2")))
|
solve(inp, h.Atoi(h.OptArgNumber(1, "2")))
|
||||||
|
2
2020/day25/input
Normal file
2
2020/day25/input
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
3248366
|
||||||
|
4738476
|
47
2020/day25/main.go
Normal file
47
2020/day25/main.go
Normal 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
2
2020/day25/testinput
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
5764801
|
||||||
|
17807724
|
Loading…
Reference in New Issue
Block a user