10
authorMart Lubbers <mart@martlubbers.net>
Thu, 10 Dec 2020 06:47:05 +0000 (07:47 +0100)
committerMart Lubbers <mart@martlubbers.net>
Thu, 10 Dec 2020 06:47:05 +0000 (07:47 +0100)
10/input [new file with mode: 0644]
10/one.icl [new file with mode: 0644]
7/one.icl

diff --git a/10/input b/10/input
new file mode 100644 (file)
index 0000000..de682dd
--- /dev/null
+++ b/10/input
@@ -0,0 +1,107 @@
+48
+171
+156
+51
+26
+6
+80
+62
+65
+82
+130
+97
+49
+31
+142
+83
+75
+20
+154
+119
+56
+114
+92
+33
+140
+74
+118
+1
+96
+44
+128
+134
+121
+64
+158
+27
+17
+101
+59
+12
+89
+88
+145
+167
+11
+3
+39
+43
+105
+16
+170
+63
+111
+2
+108
+21
+146
+77
+45
+52
+32
+127
+147
+76
+58
+37
+86
+129
+57
+133
+120
+163
+138
+161
+139
+71
+9
+141
+168
+164
+124
+157
+95
+25
+38
+69
+87
+155
+135
+15
+102
+70
+34
+42
+24
+50
+68
+169
+10
+55
+117
+30
+81
+151
+100
+162
+148
diff --git a/10/one.icl b/10/one.icl
new file mode 100644 (file)
index 0000000..cfe0e24
--- /dev/null
@@ -0,0 +1,37 @@
+module one
+
+import StdEnv
+
+read :: *File -> [Int]
+read f
+       # (ok, i, f) = freadi f
+       | not ok = []
+       = [i:read f]
+
+Start w
+       # (io, w) = stdio w
+       # ls = sort [0:read io]
+       = (one ls, two ls)
+
+one ls = uncurry (*) (foldl jolt (0, 1) [b-a\\a<-ls & b<-tl ls])
+where
+       jolt (j1, j3) 3 = (j1, j3+1)
+       jolt (j1, j3) 1 = (j1+1, j3)
+       jolt (j1, j3) _ = (j1, j3)
+
+two [a,b,c,d,e,f,g,h,i:xs]
+       | i-a <= 9 = 53 * two xs
+two [a,b,c,d,e,f,g,h:xs]
+       | h-a <= 8 = 33 * two xs
+two [a,b,c,d,e,f,g:xs]
+       | g-a <= 7 = 20 * two xs
+two [a,b,c,d,e,f:xs]
+       | f-a <= 6 = 12 * two xs
+two [a,b,c,d,e:xs]
+       | e-a <= 5 = 7 * two xs
+two [a,b,c,d:xs]
+       | d-a <= 4 = 4 * two xs
+two [a,b,c:xs]
+       | c-a <= 3 = 2 * two xs
+two [x:xs] = two xs
+two [] = 1
index 0c3b8a1..8b3eef3 100644 (file)
--- a/7/one.icl
+++ b/7/one.icl
@@ -17,10 +17,10 @@ read f
 Start w
        # (io, w) = stdio w
        # bag = fromList (makeBag (read io))
-       = (one ['shiny gold'] bag, dec $ two ['shiny gold'] bag)
+       = (one bag ['shiny gold'], dec $ two bag ['shiny gold'])
 
-one color bag = dec $ length $ filter id $ map (canContain bag color) $ keys bag
-two color bag = inc $ sum [n*two c bag\\(n, c)<-findWithDefault [] color bag]
+one bag color = dec $ length $ filter id $ map (canContain bag color) $ keys bag
+two bag color = inc $ sum [n*two bag c\\(n, c)<-findWithDefault [] color bag]
 
 makeBag :: [Char] -> [([Char], [(Int, [Char])])]
 makeBag ls = [(b, mkItem c)\\[b,c]<-map (split [' contain ']) $ split ['.\n'] ls]