make more elegant
[aoc20.git] / 3 / one.icl
1 module one
2
3 import StdEnv
4
5 read :: *File -> [[Int]]
6 read f
7 # (l, f) = freadline f
8 | l.[size l - 1] <> '\n' = []
9 = [let c = [if (c == '#') 1 0\\c<-:l | c <> '\n'] ++ c in c:read f]
10
11 Start w
12 # (io, w) = stdio w
13 # ls = read io
14 = (one ls, two ls)
15
16 one ls :== slope ls (3, 1)
17
18 two :: [[Int]] -> Int
19 two ls = prod (map (slope ls) [(1,1), (3,1), (5,1), (7,1), (1,2)])
20
21 slope :: [[Int]] (Int, Int) -> Int
22 slope [] _ = 0
23 slope xs=:[[c:_]:_] d=:(right, down) = c + slope (map (drop right) (drop down xs)) d