-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay12.hs
More file actions
33 lines (28 loc) · 949 Bytes
/
Copy pathDay12.hs
File metadata and controls
33 lines (28 loc) · 949 Bytes
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
module Day12
( part1
, part2
) where
import Assembunny (decompile, parseProgram)
import Data.Either (fromRight)
import Data.Text (Text)
import Math.NumberTheory.Recurrences.Linear (fibonacci)
import Text.Megaparsec (parse)
result :: Int -> Int
result c = fibonacci (28 + c) + 14 ^ 2
printResult :: Int -> Text -> String
printResult c input =
program
++ "Lines 1-8 set values, lines 9 to 15 calculate the (28 + "
++ show c
++ ")th fibonacci number lines 16 to 22 add 14 squared, for a result of\n"
++ show (result c)
where
program =
decompile
. fromRight (error "couldn't parse input")
. parse parseProgram ""
$ input
part1 :: Bool -> Text -> String
part1 _ = printResult 0
part2 :: Bool -> Text -> String
part2 _ _ = show . result $ 7