From a3d0bcde24045672981ff1159466745fa7dbcc22 Mon Sep 17 00:00:00 2001 From: shu Date: Wed, 4 Dec 2019 09:30:38 +0100 Subject: [PATCH] =?UTF-8?q?Stole=20Fichte=E2=80=99s=20parse=20idea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2019/day4/day4.hs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/2019/day4/day4.hs b/2019/day4/day4.hs index 26684d2..181f33b 100644 --- a/2019/day4/day4.hs +++ b/2019/day4/day4.hs @@ -1,16 +1,10 @@ import Data.List main = do - print (day4a 130254 678275) - print (day4b 130254 678275) + print (day4 p [130254..678275]) + print (day4 p' [130254..678275]) -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 $ show x then acc+1 else acc) - | otherwise = acc - where x' = succ x +day4 p = sum . map (fromEnum . p . show) p x | sort x /= x = False