Eban numbers: Difference between revisions

m
(Added Wren)
Line 657:
{{trans|Julia}}
<lang haskell>{-# LANGUAGE NumericUnderscores #-}
import Data.List (find, intercalate)
import Text.Printf (printf)
import Data.List.Split (chunksOf)
 
isEban :: Int -> Bool
Line 668 ⟶ 669:
z = b : map (\x -> if x >= 30 && x <= 66 then x `mod` 10 else x) [m, t, r3]
 
ebans :: [Int] -> [(IntString, IntString)]
ebans = go
where
Line 674 ⟶ 675:
go [] = []
go (x:xs) = case find (\(_, e) -> x < e) ebanCount of
Just (c, e) -> (thousands x, thousands $ pred c) : go xs
Nothing -> go xs
 
thousands:: Int -> String
thousands = reverse . intercalate "," . chunksOf 3 . reverse . show
 
main :: IO ()
main = do
uncurry (printf "eban numbers up to and including 1000: %2d2s\n%s\n\n") $ r [1..1000]
uncurry (printf "eban numbers between 1000 and 4000: %2d2s\n%s\n\n") $ r [1000..4000]
mapM_ (uncurry (printf "eban numbers up and including %10d13s: %4d5s\n")) ebanCounts
where
ebanCounts = ebans [ 10_000
Line 689 ⟶ 693:
, 100_000_000
, 1_000_000_000 ]
r = ((,) <$> thousands . length <*> show) . filter isEban</lang>
{{out}}
<pre>
Line 698 ⟶ 702:
[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 10000 10,000: 79
eban numbers up and including 100000 100,000: 399
eban numbers up and including 1000000 1,000,000: 399
eban numbers up and including 10000000 10,000,000: 15991,599
eban numbers up and including 100000000 100,000,000: 79997,999
eban numbers up and including 10000000001,000,000,000: 79997,999
</pre>
 
Anonymous user