import StdEnv
import Data.List
+import Data.Func
import StdMaybe
read :: *File -> [Int]
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