Day 23 - off-by-one error >:[

This commit is contained in:
Jonathan Chan 2017-12-24 01:14:34 -08:00
parent dbd0b00676
commit adec393e53
2 changed files with 3 additions and 4 deletions

3
23.hs
View File

@ -61,8 +61,7 @@ runInstructions instructions state@(State _ pos cnt) =
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
foldr (\b h -> h + (fromEnum . or . map (\d -> b `mod` d == 0) $ [2..(floor . sqrt . fromIntegral) b])) 0 [108100, 108117..125100]
main :: IO ()
main = do

4
23b.c
View File

@ -13,14 +13,14 @@ unsigned int naiveCount() {
}
}
}
h += !f
h += !f;
}
return h;
}
unsigned int count() {
unsigned short h = 0;
for (long b = 108100; b < 125100; b += 17) {
for (long b = 108100; b <= 125100; b += 17) {
bool f = true;
for (unsigned short d = 2; f && d * d <= b; d++) {
if (b % d == 0) {