repositories
/
aoc20.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
45dde8c
)
less code
author
Mart Lubbers
<mart@martlubbers.net>
Wed, 9 Dec 2020 08:33:06 +0000
(09:33 +0100)
committer
Mart Lubbers
<mart@martlubbers.net>
Wed, 9 Dec 2020 08:33:06 +0000
(09:33 +0100)
9/one.icl
patch
|
blob
|
history
diff --git
a/9/one.icl
b/9/one.icl
index
6371650
..
9facd44
100644
(file)
--- a/
9/one.icl
+++ b/
9/one.icl
@@
-2,6
+2,7
@@
module one
import StdEnv
import Data.List
import StdEnv
import Data.List
+import Data.Func
import StdMaybe
read :: *File -> [Int]
import StdMaybe
read :: *File -> [Int]
@@
-19,15
+20,11
@@
one = last o pre
pre l
# (preamble, [num:rest]) = splitAt 25 l
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
= [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
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