--- /dev/null
+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
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]