Eban numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Tailspin}}: syntax update)
Line 657: Line 657:
{{trans|Julia}}
{{trans|Julia}}
<lang haskell>{-# LANGUAGE NumericUnderscores #-}
<lang haskell>{-# LANGUAGE NumericUnderscores #-}
import Data.List (find, intercalate)
import Data.List (intercalate)
import Text.Printf (printf)
import Text.Printf (printf)
import Data.List.Split (chunksOf)
import Data.List.Split (chunksOf)
Line 669: Line 669:
z = b : map (\x -> if x >= 30 && x <= 66 then x `mod` 10 else x) [m, t, r3]
z = b : map (\x -> if x >= 30 && x <= 66 then x `mod` 10 else x) [m, t, r3]


ebans :: [Int] -> [(String, String)]
ebans = map f
where
ebans = go
f x = (thousands x, thousands $ length $ filter isEban [1..x])
where
ebanCount = zip [1..] (filter isEban [1..])
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:: Int -> String