The sieve of Sundaram: Difference between revisions
→{{header|Haskell}}: Dropped use of Data.Set
(→{{header|Haskell}}: Added a draft version in Haskell) |
(→{{header|Haskell}}: Dropped use of Data.Set) |
||
Line 284:
<lang haskell>import Data.List (intercalate, transpose)
import Data.List.Split (chunksOf)
import Text.Printf (printf)
Line 290 ⟶ 289:
sundaram :: Integral a => a -> [a]
sundaram n = succ . (2 *) <$> gaps [1 ..] excluded
]▼
where
m = div (pred n) 2
excluded =
let fi
j <-
▲ ]
nSundaramPrimes ::
Line 310 ⟶ 304:
nSundaramPrimes n =
sundaram $ floor $ (2.4 * n * log n) / 2
Line 319 ⟶ 312:
(putStrLn . table " " . chunksOf 10) $
show <$> nSundaramPrimes 100
------------------------- GENERIC ------------------------
gaps _ [] = []
gaps (x : xs) yys@(y : ys)
| x >= y = gaps xs ys
| otherwise = x : gaps xs yys
table :: String -> [[String]] -> String
|