Anonymous user
Eban numbers: Difference between revisions
m
→{{header|Haskell}}
(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] -> [(
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: %
uncurry (printf "eban numbers between 1000 and 4000: %
mapM_ (uncurry (printf "eban numbers up and including %
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
eban numbers up and including
eban numbers up and including
eban numbers up and including
eban numbers up and including
eban numbers up and including
</pre>
|