From d040b97bc8186b4ed261c901e770eccb2a3cc885 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Sun, 10 Jan 2021 10:47:08 +0100 Subject: [PATCH] Add 2020 day 25 p1 --- haskellAoC/inputs/2020/25 | 2 ++ haskellAoC/src/Y2020/Day25.hs | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 haskellAoC/inputs/2020/25 diff --git a/haskellAoC/inputs/2020/25 b/haskellAoC/inputs/2020/25 new file mode 100644 index 0000000..19182ea --- /dev/null +++ b/haskellAoC/inputs/2020/25 @@ -0,0 +1,2 @@ +3418282 +8719412 diff --git a/haskellAoC/src/Y2020/Day25.hs b/haskellAoC/src/Y2020/Day25.hs index 77600cf..d517c90 100644 --- a/haskellAoC/src/Y2020/Day25.hs +++ b/haskellAoC/src/Y2020/Day25.hs @@ -1,6 +1,20 @@ module Y2020.Day25 (y20day25) where +doTransform :: Int -> Int -> Int +doTransform subjNumber n = rem (n * subjNumber) 20201227 + +getLoopSize :: Int -> Int +getLoopSize targetPK = length $ takeWhile (/= targetPK) $ iterate (doTransform 7) 1 + +transformNtimes :: Int -> Int -> Int +transformNtimes subjNumber loopSize = head $ drop loopSize $ iterate (doTransform subjNumber) 1 + y20day25 :: [String] -> (String, String) y20day25 input = (part1, part2) - where part1 = "WIP" - part2 = "WIP" + where part1 = show $ transformNtimes doorpk cardls + part2 = show $ "WIP" + input' = map read input :: [Int] + doorpk = input' !! 0 + cardpk = input' !! 1 + -- doorls = getLoopSize doorpk + cardls = getLoopSize cardpk