10
[aoc20.git] / 10 / one.icl
1 module one
2
3 import StdEnv
4
5 read :: *File -> [Int]
6 read f
7 # (ok, i, f) = freadi f
8 | not ok = []
9 = [i:read f]
10
11 Start w
12 # (io, w) = stdio w
13 # ls = sort [0:read io]
14 = (one ls, two ls)
15
16 one ls = uncurry (*) (foldl jolt (0, 1) [b-a\\a<-ls & b<-tl ls])
17 where
18 jolt (j1, j3) 3 = (j1, j3+1)
19 jolt (j1, j3) 1 = (j1+1, j3)
20 jolt (j1, j3) _ = (j1, j3)
21
22 two [a,b,c,d,e,f,g,h,i:xs]
23 | i-a <= 9 = 53 * two xs
24 two [a,b,c,d,e,f,g,h:xs]
25 | h-a <= 8 = 33 * two xs
26 two [a,b,c,d,e,f,g:xs]
27 | g-a <= 7 = 20 * two xs
28 two [a,b,c,d,e,f:xs]
29 | f-a <= 6 = 12 * two xs
30 two [a,b,c,d,e:xs]
31 | e-a <= 5 = 7 * two xs
32 two [a,b,c,d:xs]
33 | d-a <= 4 = 4 * two xs
34 two [a,b,c:xs]
35 | c-a <= 3 = 2 * two xs
36 two [x:xs] = two xs
37 two [] = 1