3 -- import Math.NumberTheory.Moduli.DiscreteLogarithm
4 -- import Data.Finite (Finite, modulo, getFinite)
5 -- import GHC.TypeNats (KnownNat)
10 newtype MExp = MExp Integer
13 instance Semigroup MExp where
14 (MExp a) <> (MExp b) = MExp $ (a * b) `mod` modularBase
20 modularBase :: Integer
21 modularBase = 20201227
25 do text <- readFile "data/advent25.txt"
26 let [cardKey, doorKey] = map read $ lines text
27 print $ part1 cardKey doorKey
29 part1 cardKey doorKey = publicKey
30 where cardRounds = findRounds cardKey
31 MExp publicKey = stimes cardRounds (MExp doorKey)
33 findRounds :: Integer -> Integer
34 findRounds target = fst $ until (foundRounds t) countingExponential (0, seed)
38 foundRounds :: MExp -> (Integer, MExp) -> Bool
39 foundRounds target (_n, v) = v == target
41 countingExponential :: (Integer, MExp) -> (Integer, MExp)
42 countingExponential (n, v) = (n + 1, v <> subject)