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