From a07b6fba16eb091904f3c3d00c3a5e3636e36ce2 Mon Sep 17 00:00:00 2001 From: shu Date: Wed, 4 Dec 2019 08:02:39 +0100 Subject: [PATCH] Day 4: Initial version Now to look at other solutions --- 2019/day4/day4.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 2019/day4/day4.hs diff --git a/2019/day4/day4.hs b/2019/day4/day4.hs new file mode 100644 index 0000000..bc5fd91 --- /dev/null +++ b/2019/day4/day4.hs @@ -0,0 +1,28 @@ +import Data.List + +main = do + let bottom = 130254 + let top = 678275 + print (day4a bottom top) + print (day4b bottom top) + +day4a bottom top = dumbbrute bottom top p 0 +day4b bottom top = dumbbrute bottom top p' 0 + +dumbbrute x y p acc + | x'<=y = dumbbrute x' y p (if p (numexpl x) then acc+1 else acc) + | otherwise = acc + where x' = succ x + +p x + | sort x /= x = False + | nub x == x = False + | otherwise = True + +p' x + | sort x /= x = False + | 2 `elem` (map length $ group x) = True + | otherwise = False + +numexpl 0 = [] +numexpl x = numexpl (x `div` 10) ++ [x `mod` 10]