From 319d98c6174a959108bf4c0bf3722abc9e9133c6 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 9 Dec 2020 09:33:06 +0100 Subject: [PATCH] less code --- 9/one.icl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/9/one.icl b/9/one.icl index 6371650..9facd44 100644 --- a/9/one.icl +++ b/9/one.icl @@ -2,6 +2,7 @@ module one import StdEnv import Data.List +import Data.Func import StdMaybe read :: *File -> [Int] @@ -19,15 +20,11 @@ one = last o pre pre l # (preamble, [num:rest]) = splitAt 25 l - | isEmpty [()\\a<-preamble, b<-preamble | a + b == num] = [num] + | isEmpty [()\\(x, y)<-diag2 preamble preamble | x+y==num] = [num] = [num:pre (tl l)] two ls # ls = fst (splitAt 25 ls) ++ pre ls - # a = sort (hd (calc (last ls) ls)) - = (last a + hd a) + = let a = calc (last ls) ls in last a + hd a where -// calc :: Int [Int] -> (Int, Int) - calc num xs = hd (filter (not o isEmpty) [calc` num l\\l<-tails xs]) - - calc` num xs = filter ((==)num o sum) (dropWhile ((<) num o sum) (inits xs)) + calc num = sort o hd o hd o filter (not o isEmpty) o map (filter ((==)num o sum) o dropWhile ((<)num o sum) o inits) o tails -- 2.20.1