The sieve of Sundaram: Difference between revisions
Undo revision 340192 by Hout (talk)
(→{{header|Haskell}}: Dropped use of Data.Set) |
|||
Line 284:
<lang haskell>import Data.List (intercalate, transpose)
import Data.List.Split (chunksOf)
import qualified Data.Set as S
import Text.Printf (printf)
Line 289 ⟶ 290:
sundaram :: Integral a => a -> [a]
sundaram n =
[ succ (2 * x)
| x <- [1 .. m],
x `S.notMember` excluded
where
m = div (pred n) 2
excluded =
j <- [i .. floor ((fm - fi) / succ (2 * fi))]
▲ ]
]
nSundaramPrimes ::
Line 304 ⟶ 310:
nSundaramPrimes n =
sundaram $ floor $ (2.4 * n * log n) / 2
Line 312 ⟶ 319:
(putStrLn . table " " . chunksOf 10) $
show <$> nSundaramPrimes 100
table :: String -> [[String]] -> String
|