-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.hs
40 lines (33 loc) · 766 Bytes
/
run.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
35
36
37
38
39
40
{-# LANGUAGE TypeApplications #-}
import Data.Bifunctor (second)
import Data.Maybe
import Data.List
parseAll =
map (read @Int) . lines
sequences n nums =
let (h, t) = splitAt n nums
in
zip t $ scanl (\curr x -> drop 1 curr ++ [x]) h t
sums xs = [x + y | x <- xs, y <- xs, x /= y]
diffs xs = zipWith (-) (drop 1 xs) xs
findSum t =
diffs
. head
. filter ((== t) . last)
. filter ((>= 2) . length)
. map (takeWhile (<= t) . scanl (+) 0)
. tails
part1 =
fst
. head
. filter (not . uncurry elem)
. map (second sums)
. sequences 25
part2 input =
let target = part1 input
s = findSum target input
in minimum s + maximum s
main = do
input <- parseAll <$> readFile "input.txt"
print (part1 input)
print (part2 input)