-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay25.hs
34 lines (28 loc) · 1.21 KB
/
Day25.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE DataKinds #-}
module Day25
( part1
, part2
) where
import Data.Maybe (fromJust)
import GHC.TypeLits (Natural)
import Math.NumberTheory.Moduli.Class (Mod, getVal)
import Math.NumberTheory.Moduli.Multiplicative (discreteLogarithm,
isMultElement,
isPrimitiveRoot)
import Math.NumberTheory.Moduli.Singleton (CyclicGroup,
cyclicGroup)
findDiscreteLogarithm :: Int -> Int -> Natural
findDiscreteLogarithm root remainder = discreteLogarithm cg rt rem
where
cg = fromJust cyclicGroup :: CyclicGroup Integer 20201227
rt = fromJust . isPrimitiveRoot cg . fromIntegral $ root
rem = fromJust . isMultElement . fromIntegral $ remainder
findKey :: [Int] -> Integer
findKey [cpk, dpk] = ek
where
dl = findDiscreteLogarithm 7 cpk
ek = getVal (fromIntegral dpk ^ dl :: Mod 20201227)
part1 :: Bool -> String -> String
part1 _ = show . findKey . map read . lines
part2 :: Bool -> String -> String
part2 _ _ = "Part 2"