Creating a Prime Sieve with Boolean Expressions

In summary, To create a prime sieve, you need to start by creating a certain number of boolean variables. These variables are then used to sieve out numbers by classifying them as false. You can create a large group of boolean variables by using a loop with the following syntax: p(i) = false, where i is the index of the variable. To create a large group of boolean variables, you can create an array with a desired size, such as X = 1000, and then use a loop to assign false values to each index.
  • #1
JasonRox
Homework Helper
Gold Member
2,386
4
I'm trying to create a sieve (prime sieve). A nice quick simple one using boolean expressions.

I remember on Visual Basics it began by creating like X number of boolean variables and then sieve them out by classifying them as false... and so on.

How to a create a large group of boolean variables?

I think it was something like p(i) and i=X, which X determined how many to create. It was something like this I think.

So, technically i is like a variable itselt because when I go through the loop, I should be able to go through steps like...

p(4) = false;
p(6) = false;
p(8) = false;

... all the way until I reach 2X.

So, how do you create this variable?

Thanks, I appreciate it.
 
Technology news on Phys.org
  • #2
Create as big of an array as you like.

int X = 1000 ;

boolean [] p = new boolean[X];
 
  • #3
Thanks a lot.

I'll see how it turns out.
 

1. What is a prime sieve?

A prime sieve is a mathematical algorithm used to find all prime numbers up to a given limit. It works by eliminating multiples of each prime number as it iterates through a range of numbers, leaving behind only the prime numbers.

2. How does a prime sieve work?

A prime sieve works by creating a list of numbers up to a given limit, then marking off all multiples of each prime number as it iterates through the list. This leaves only the prime numbers in the list.

3. What is a Boolean expression?

A Boolean expression is a mathematical statement that evaluates to either true or false. It can contain variables, logical operators such as "and", "or", and "not", and comparison operators such as "equals" and "greater than".

4. Why use Boolean expressions in a prime sieve?

Boolean expressions are useful in a prime sieve because they allow us to easily check if a number is a multiple of a prime number. By using Boolean expressions, we can efficiently mark off multiples of prime numbers and find the remaining prime numbers in a given range.

5. What are the advantages of using a prime sieve with Boolean expressions?

Using a prime sieve with Boolean expressions allows for a more efficient and faster way to find prime numbers compared to traditional methods. It also allows for easy customization and flexibility in terms of the range of numbers and the number of primes to be found.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
10K
  • Set Theory, Logic, Probability, Statistics
Replies
21
Views
1K
  • Programming and Computer Science
2
Replies
37
Views
2K
  • Programming and Computer Science
Replies
2
Views
3K
  • Thermodynamics
Replies
6
Views
699
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Quantum Physics
Replies
5
Views
1K
  • Set Theory, Logic, Probability, Statistics
2
Replies
40
Views
6K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top