-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay2.hs
More file actions
29 lines (23 loc) · 749 Bytes
/
Day2.hs
File metadata and controls
29 lines (23 loc) · 749 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
module Day2
( part1
, part2
) where
import Intcode (evalIntcode, initialise, update)
goal :: Int
goal = 19690720
findNounVerb :: String -> Int
findNounVerb inst =
(\(a, b) -> 100 * a + b) . head . filter ((== goal) . evalIntcode . nounVerb) $
[(x, y) | x <- [0 .. 99], y <- [0 .. 99]]
where
nounVerb (a, b) = update 1 a . update 2 b . initialise $ inst
restoreGravityAssist :: Bool -> String -> Int
restoreGravityAssist test
| test = evalIntcode . initialise
| otherwise = evalIntcode . update 1 12 . update 2 2 . initialise
part1 :: Bool -> String -> String
part1 test = show . restoreGravityAssist test
part2 :: Bool -> String -> String
part2 test
| test = const "testing"
| otherwise = show . findNounVerb