Questions tagged [sieve]

Sieves are a type of algorithm used e.g. in finding primes with the sieve of Eratosthenes, sieve of Atkin etc. "Sieving" refers to gradual dismissal of directly generated sequences of numbers as possible candidates, until only the desired numbers are left.

Sieves are a type of algorithm used e.g. in finding primes with the sieve of Eratosthenes, sieve of Atkin etc., finding lucky numbers, or in integer factorization. "Sieving" the candidate numbers refers to gradual dismissal of directly generated sequences of (in that context, composite) numbers as possible candidates, until only the desired (e.g. prime) numbers are left.

For the unrelated email filtering language, see .

198 questions
1
vote
0 answers

Sieve add message to body

I want to add a Sieve filter rule that add message to body. It worked to add a message to the subject. if allof(not address :domain :is ["from"] ["example.com""], not header :contains "Subject" ["[TEXT]"]) { if header :matches "Subject" "*" …
WhoAmI
  • 33
  • 5
1
vote
0 answers

How can I replicate Scratch's "item X in list" function in Python?

I'm relatively inexperienced with Python, and I'm attempting to convert an old prime number sieve script I made on Scratch to the Python language. The original Scratch script has a portion that goes like this: repeat until item Divisor of PrimeList…
1
vote
0 answers

Mailcow sieve script that removes attachments and adds a message to the body

I'm trying to find out how to remove non-whitelisted attachments (by mime type) (f.e. zip, exe, ...) and append a message about the removed attachments. I found this: https://superuser.com/a/1502589 And it worked to add a message to the subject. But…
cottton
  • 1,522
  • 14
  • 29
1
vote
1 answer

Choosing the size of the segment in segmented sieve of Eratosthenes

I made this segmented sieve that uses wheel factorization. Here you find the explanation. By setting the wheel size to 210 and using a segment vector uint8_t of size 277140 = 6 * (11 * 13 * 17 * 19 + 1) = nB*(segment_size+1) the sieve is fast enough…
user140242
  • 159
  • 6
1
vote
2 answers

Need help to understand some of the SICP streams examples

I'm trying to understand how this function works. (define (sieve stream) (cons-stream (stream-car stream) (sieve (stream-filter (lambda (x) (not (divisible? x (stream-car stream)))) (stream-cdr…
1
vote
2 answers

Can this prime sieve code be further simplified in Haskell?

The code works well primes = next [2 ..] where next (p : ps) = p : next ts where ts = filter (\x -> mod x p /= 0) ps Just GHCI think there is a incomplete patter in next. Well, this is correct from a grammatical point of…
Sid
  • 13
  • 3
1
vote
0 answers

If the time complexity of Sieve of Atkins is better than Sieve of Eratosthenes, why does Eratosthenes always have a quicker runtime

I'm doing a project on Sieve of Atkins and I was exploring why this algorithm was created. From what I understood was that it was a way of finding prime numbers and it ran faster than Sieve of Eratosthenes. But from what I've read, Sieve of Atkins…
1
vote
2 answers

Modified Sieve for finding Prime Numbers in Scheme

I am working on coming up with a solution for coming with a list of prime numbers using the Sieve of Eratosthenes. So the program is supposed to find prime numbers up to a specific number "n". I believe I have come up with an incomplete solution but…
1
vote
1 answer

Why does Sieve behave strangely on a base64 subject line?

I'm trying to get the message filtered by Sieve by the subject line: Subject: =?utf-8?B?0K3Qu9C10LrRgtGA0L7QvdC90YvQuSDRh9C10Log0L/QviDQ?= =?utf-8?B?t9Cw0LrQsNC30YMgMTY5MzQwMTktMDA4Ng==?= This filter does get the message discarded: if header…
nekr0z
  • 23
  • 4
1
vote
1 answer

Time complexity of sieve algorithm

Unlike the traditional sieve of Eratosthenes: n=10000000 sieve = [True] * n for i in range(3,int(n**0.5)+1,2): if sieve[i]: sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1) sieve=[2] + [i for i in range(3,n,2) if sieve[i]] What is the time…
1
vote
2 answers

Efficient (O(n^2)) Sieve of Sundaram in Haskell

There are many answers on SO explaining how to implement the Sieve of Sundaram in Haskell but they're all... really inefficient? All solutions that I have seen work like this: Figure out the numbers <= n to exclude Filter these from [1..n] Modify…
Peter
  • 2,919
  • 1
  • 16
  • 35
1
vote
3 answers

Sieve Of Eratosthenes in O(n)

I recently came across an article that claimed that it can find all primes less than n in O(n) using an efficient Sieve Of Eratosthenes. However I am unable to see how it is…
levio_sa
  • 123
  • 9
1
vote
2 answers

How to send a single request instead of two requests when using sieve in asp core for paging?

I write this query with the aim of getting users with paging. I'm using Sieve for paging and filtering and sorting, but I have a problem with this Query : I intend to send a single request to the database and just return me this data : public class…
mr coder
  • 199
  • 2
  • 14
1
vote
1 answer

Overcoming The Boolean Input Tests in the Codewars Kata: "Master your primes: sieve with memoization" - Ruby

I'm currently doing the 5kyu "Master your primes: sieve with memoization" kata on Codewars. The challenge gives you a cached array of the first 4 prime numbers, and you must check if n (e.g. 5) is a prime in that array, if so, return true. If…
user12947930
1
vote
0 answers

Index out of range error sieving B-smooth numbers with logarithms

So I have been trying to implement the quadratic sieve and I did step 1 which is(in code): f = 44 b = ceil(sqrt(n)) factorBase = [i for i in genPrimes(f) if jacobi(n, i) == 1] t = [modInverse(n, p) for p in factorBase] sol1 = [(t[i] - b) %…