From dbd0b00676f6595a68effe205e763f504831d9d5 Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Sat, 23 Dec 2017 20:30:46 -0800 Subject: [PATCH] Day 23 - added implementation of part 2 in Haskell --- 23a.hs => 23.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) rename 23a.hs => 23.hs (88%) diff --git a/23a.hs b/23.hs similarity index 88% rename from 23a.hs rename to 23.hs index 1900eb2..722f1ea 100644 --- a/23a.hs +++ b/23.hs @@ -59,7 +59,13 @@ runInstructions instructions state@(State _ pos cnt) = if pos >= length instructions then cnt else let !nextState = instructions `index` pos $ state in runInstructions instructions nextState +count :: Int +count = + foldr (\b h -> h + (fromEnum . any id . map ((== 0) . (b `mod`)) $ [2..squareroot b])) 0 [108100, 108117..125083] + where squareroot = floor . sqrt . fromIntegral + main :: IO () main = do instructions <- fromList . map parseLine . lines <$> readFile "23.txt" - print $ runInstructions instructions (State (V.replicate 8 0) 0 0) \ No newline at end of file + print $ runInstructions instructions (State (V.replicate 8 0) 0 0) + print $ count \ No newline at end of file