From: Mart Lubbers Date: Wed, 9 Dec 2020 08:33:06 +0000 (+0100) Subject: less code X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=319d98c6174a959108bf4c0bf3722abc9e9133c6;p=aoc20.git less code --- 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