From 755844d13e3e1c3521c4d8c5033706d6abfe0b81 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 10 Dec 2020 08:16:44 +0100 Subject: [PATCH] nicer version --- 10/one.icl | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/10/one.icl b/10/one.icl index cfe0e24..32ffe8b 100644 --- a/10/one.icl +++ b/10/one.icl @@ -2,6 +2,9 @@ module one import StdEnv +import Data.List +import Data.Func + read :: *File -> [Int] read f # (ok, i, f) = freadi f @@ -13,25 +16,10 @@ Start w # ls = sort [0:read io] = (one ls, two ls) -one ls = uncurry (*) (foldl jolt (0, 1) [b-a\\a<-ls & b<-tl 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 +two ls = prod [[0,1,2,4,7,12,20,33,53]!!length l\\l<-group [b-a\\a<-ls & b<-tl ls] | all ((==)1) l] -- 2.20.1