Eban numbers: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→Algorithmically generate / count: Fix comment: Perl 6 --> Raku) |
No edit summary |
||
Line 653: | Line 653: | ||
eban numbers up to and including 1000000000: |
eban numbers up to and including 1000000000: |
||
count = 7999 |
count = 7999 |
||
</pre> |
|||
=={{header|Haskell}}== |
|||
<lang haskell>{-# LANGUAGE NumericUnderscores #-} |
|||
anyPass :: [a -> Bool] -> a -> Bool |
|||
anyPass [] _ = False |
|||
anyPass (f:fs) x = f x || anyPass fs x |
|||
isEban :: Int -> Bool |
|||
isEban n = all (anyPass [(==0), (==2), (==4), (==6)]) z |
|||
where |
|||
(b, r1) = n `quotRem` (10 ^ 9) |
|||
(m, r2) = r1 `quotRem` (10 ^ 6) |
|||
(t, r3) = r2 `quotRem` (10 ^ 3) |
|||
z = [b] <> map (\x -> if 30 <= x && x <= 66 then x `mod` 10 else x) [m, t, r3] |
|||
main = do |
|||
putStrLn $ "eban numbers up to and including 1000: " ++ r [1..1000] |
|||
putStrLn $ "eban numbers between 1000 and 4000: " ++ r [1000..4000] |
|||
putStrLn "" |
|||
putStrLn $ "eban numbers up and including 10,000: " ++ t [1..10_000] |
|||
putStrLn $ "eban numbers up and including 100,000: " ++ t [1..100_000] |
|||
putStrLn $ "eban numbers up and including 1,000,000: " ++ t [1..1_000_000] |
|||
putStrLn $ "eban numbers up and including 10,000,000: " ++ t [1..10_000_000] |
|||
where |
|||
r = (\(c, xs) -> show c <> "\n" <> show xs <> "\n") . (\xs -> (length xs, xs)) . filter isEban |
|||
t = show . length . filter isEban</lang> |
|||
{{out}} |
|||
<pre> |
|||
eban numbers up to and including 1000: 19 |
|||
[2,4,6,30,32,34,36,40,42,44,46,50,52,54,56,60,62,64,66] |
|||
eban numbers between 1000 and 4000: 21 |
|||
[2000,2002,2004,2006,2030,2032,2034,2036,2040,2042,2044,2046,2050,2052,2054,2056,2060,2062,2064,2066,4000] |
|||
eban numbers up and including 10,000: 79 |
|||
eban numbers up and including 100,000: 399 |
|||
eban numbers up and including 1,000,000: 399 |
|||
eban numbers up and including 10,000,000: 1599 |
|||
</pre> |
</pre> |
||