DEV Community

Discussion on: Advent of Code 2020 Solution Megathread - Day 25: Combo Breaker

Collapse
 
bgaster profile image
Benedict Gaster

Happy Holidays! Sad that it's over! Pleased that it was a quick one today as I was thinking I'd have to do it tomorrow... Anyway all pretty straightforward in any language and so my choice Haskell:

card = 2069194
cardSize = size card 1 0

door = 16426071
doorSize = size 7 door 1 0

step s c = c * s `mod` 20201227

size s k c n | k == c = n
             | otherwise = size s k (step s c) (n+1)

private s c 0 = c
private s c n = private s (step s c) (n-1)

main = print (private card 1 doorSize)
Enter fullscreen mode Exit fullscreen mode