nicer version
[aoc20.git] / 10 / one.icl
1 module one
2
3 import StdEnv
4
5 import Data.List
6 import Data.Func
7
8 read :: *File -> [Int]
9 read f
10 # (ok, i, f) = freadi f
11 | not ok = []
12 = [i:read f]
13
14 Start w
15 # (io, w) = stdio w
16 # ls = sort [0:read io]
17 = (one ls, two ls)
18
19 one ls = uncurry (*) $ foldl jolt (0, 1) [b-a\\a<-ls & b<-tl ls]
20 where
21 jolt (j1, j3) 3 = (j1, j3+1)
22 jolt (j1, j3) 1 = (j1+1, j3)
23 jolt (j1, j3) _ = (j1, j3)
24
25 two ls = prod [[0,1,2,4,7,12,20,33,53]!!length l\\l<-group [b-a\\a<-ls & b<-tl ls] | all ((==)1) l]