repositories
/
aoc20.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d8eab5b
)
make more elegant
author
Mart Lubbers
<mart@martlubbers.net>
Thu, 3 Dec 2020 06:04:31 +0000
(07:04 +0100)
committer
Mart Lubbers
<mart@martlubbers.net>
Thu, 3 Dec 2020 07:55:37 +0000
(08:55 +0100)
3/one.icl
patch
|
blob
|
history
diff --git
a/3/one.icl
b/3/one.icl
index
cd566ea
..
3bac706
100644
(file)
--- a/
3/one.icl
+++ b/
3/one.icl
@@
-2,25
+2,22
@@
module one
import StdEnv
import StdEnv
-read :: *File -> [
String
]
+read :: *File -> [
[Int]
]
read f
# (l, f) = freadline f
| l.[size l - 1] <> '\n' = []
read f
# (l, f) = freadline f
| l.[size l - 1] <> '\n' = []
- = [l
% (0, size l - 2)
:read f]
+ = [l
et c = [if (c == '#') 1 0\\c<-:l | c <> '\n'] ++ c in c
:read f]
Start w
# (io, w) = stdio w
# ls = read io
Start w
# (io, w) = stdio w
# ls = read io
- = (one
0
ls, two ls)
+ = (one ls, two ls)
-one :: Int [String] -> Int
-one _ [] = 0
-one i [x:xs] = if (x.[i rem size x] == '#') 1 0 + one (i+3) xs
+one ls :== slope ls (3, 1)
-two :: [
String
] -> Int
-two ls = prod
[slope right down 0 ls\\(right, down)<-[(1,1), (3,1), (5,1), (7,1), (1,2)]]
+two :: [
[Int]
] -> Int
+two ls = prod
(map (slope ls) [(1,1), (3,1), (5,1), (7,1), (1,2)])
-slope :: Int Int Int [String] -> Int
-slope right down i [x:xs]
- = (if (x.[i rem size x] == '#') 1 0) + slope right down (i + right) (drop (dec down) xs)
-slope _ _ _ [] = 0
+slope :: [[Int]] (Int, Int) -> Int
+slope [] _ = 0
+slope xs=:[[c:_]:_] d=:(right, down) = c + slope (map (drop right) (drop down xs)) d