Day 23 - off-by-one error >:[
This commit is contained in:
parent
dbd0b00676
commit
adec393e53
3
23.hs
3
23.hs
|
@ -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
4
23b.c
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue