-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay1.hs
32 lines (26 loc) · 774 Bytes
/
Day1.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
module Javran.AdventOfCode.Y2020.Day1 (
) where
import qualified Data.IntSet as IS
import Javran.AdventOfCode.Prelude
data Day1 deriving (Generic)
instance Solution Day1 where
solutionRun _ SolutionContext {getInputS, answerShow} = do
xs <- IS.fromList . fmap (read @Int) . words <$> getInputS
answerShow (head (solutions xs))
answerShow (head (solutions2 xs))
solutions :: IS.IntSet -> [] Int
solutions xs = do
x <- IS.toAscList xs
let (_, ys) = IS.split x xs
let y = 2020 - x
True <- [IS.member y ys]
pure $ x * y
solutions2 :: IS.IntSet -> [] Int
solutions2 xs = do
x <- IS.toAscList xs
let (_, ys) = IS.split x xs
y <- IS.toAscList ys
let (_, zs) = IS.split y ys
z = 2020 - x - y
True <- [IS.member z zs]
pure $ x * y * z