Calculate primes using sieve

This commit is contained in:
Manuel Thalmann 2024-06-16 15:04:30 +02:00
parent c622d4d12e
commit bfe5475ca6

View file

@ -70,6 +70,12 @@ sieve pred xs = realSieve [] xs
-- >>> sieve (\ x -> \ y -> y > x) [1, 2, 3, 1, 2, 9, 7] -- >>> sieve (\ x -> \ y -> y > x) [1, 2, 3, 1, 2, 9, 7]
-- [1,2,3,9] -- [1,2,3,9]
-- --
--------------------
-- Exercise 3 b) 1.
--------------------
-- >>> (\ n -> sieve (\ x -> \ y -> (y `mod` x) > 0) [2..n]) 100
-- [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
--
sieveC :: (a -> a -> Bool) -> [a] -> [a] sieveC :: (a -> a -> Bool) -> [a] -> [a]
sieveC pred xs = realSieve id xs sieveC pred xs = realSieve id xs
@ -80,3 +86,9 @@ sieveC pred xs = realSieve id xs
-- >>> sieve (\ x -> \ y -> y > x) [6, 2, 3, 1, 2, 9, 7] -- >>> sieve (\ x -> \ y -> y > x) [6, 2, 3, 1, 2, 9, 7]
-- [6,9] -- [6,9]
-- --
--------------------
-- Exercise 3 b) 2.
--------------------
-- >>> (\ n -> sieve (\ x -> \ y -> (y `mod` x) > 0) [2..n]) 100
-- [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
--