Day 23 - added implementation of part 2 in Haskell
This commit is contained in:
parent
cfe8ff331c
commit
dbd0b00676
|
@ -59,7 +59,13 @@ runInstructions instructions state@(State _ pos cnt) =
|
||||||
if pos >= length instructions then cnt else
|
if pos >= length instructions then cnt else
|
||||||
let !nextState = instructions `index` pos $ state in runInstructions instructions nextState
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
instructions <- fromList . map parseLine . lines <$> readFile "23.txt"
|
instructions <- fromList . map parseLine . lines <$> readFile "23.txt"
|
||||||
print $ runInstructions instructions (State (V.replicate 8 0) 0 0)
|
print $ runInstructions instructions (State (V.replicate 8 0) 0 0)
|
||||||
|
print $ count
|
Loading…
Reference in New Issue