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