```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
###
# Name: Enea Dodi
# Student ID: 2296306
# Email: dodi@chapman.edu
# Course: PHYS220/MATH220/CPSC220 Fall 2018 Assignment: CW03
###

'''Eratosthenes module
This module contains the eratosthenes function that generates
primes up to the value of positive integer input n'''
import math
def eratosthenes(n):
    '''Erastosthenes function
    Args: n - positive integer representing ceiling number
    Returns: list of all primes less than n'''
    
    #check if integer passed in is positive
    if n < 1:
        raise Exception("Please enter an integer > 0")
    
    #generates all integers up to n > 2
    nums = list(range(n))
    nums = nums[2:]
    
    #removes all even numbers
    nums = [a for a in nums if ((a % 2 != 0) or (a==2))]
    
    #removes everything that isnt a prime number
    for i in nums:
        if i > math.sqrt(n):
            break
        else:
            for counter in nums:
                if(counter!=i and counter%i==0):
                    nums.remove(counter)
            
    return nums

def gen_eratosthenes():
    n = set()
    i = 0
    a = 2
    checker = False
    while True:
        i = i + 1
        if i == 1:
            continue
        elif i == 2:
            n.add(2)
            yield 2
        else:
            checker = True
            while checker:
                checker = False
                for j in n:
                    if (a%j) == 0:
                        a = a+1
                        checker = True
                        break
            n.add(a)
            yield a

```

# The Sieve of Eratosthenes
#### Name: Enea Dodi, Gwyneth Casey, Jack Savage
#### Date: 9/27/2018

The goal of both eratosthenes and gen_eratosthenes are to single down on only the prime numbers up to a certain point. Eratosthenes takes in a parameter
n which serves as the cap where the function stops at. This function will return a list containing every prime up to that number.
gen_Eratosthenes is a little different because it is a generator. It figures out the next prime when next(generatorfunction) is called. It is infinite cause
it'll always compute the next value

I used list in the function because that was the best way to output a list (in my eyes)
For the function erastothenes, the design follows this order
1. Checks if input value is less than 1, if not, then continue. If so, then raise Exception
2. Makes a list with all values in range n.
3. removes all values before 2.
4. removes all even numbers except 2
5. checks if value in nums is > the sqrt of the input value. If it is, operation stops. If it is not, then removes a value in the list if a proceding value % that value is = to 0

<br>
<br>

##### if
\begin{align}0 & = b \% a\end{align}
#### then remove b

<br>
<br>
<br>



6. Repeats step 5 until the end of list

For the generator gen_erastothenes, the design follows this order:
1. makes a set which will hold all the prime numbers
2. uses an int for the special cases of the value being 1 ore two. Checks if the values are 1 and 2 and yields accordingly
3. checks if a number represented by 'a' is prime by checking if any of the numbers in the prime set % 0 equals 0. If any number in the set does, then simply it adds 1 to a and tries again! Once there is no number in the set that divides equally to a, a is added to the set and is yielded.





# Generating Prime Numbers
The prime number generator logic is completely different from the original function.

For the generator gen_erastothenes, the design follows this order:
1. makes a set which will hold all the prime numbers
2. uses an int for the special cases of the value being 1 ore two. Checks if the values are 1 and 2 and yields accordingly
3. checks if a number represented by 'a' is prime by checking if any of the numbers in the prime set % 0 equals 0. If any number in the set does, then simply it adds 1 to a and tries again! Once there is no number in the set that divides equally to a, a is added to the set and is yielded.

Rather than removing all numbers in a list that are not primes, this makes a set where all prime numbers are held and has a singular integer that increments by one each time a division by a number in set equals a whole number.

The next section will demostrate the generator working!




```python
#!/usr/bin/env python3 
#-*- coding: utf-8 -*-
from primesE import gen_eratosthenes as gen_eratos
g = gen_eratos()
for i in range(20):
    print(next(g))


```

6b1c667938edc988ae9cc10420ece59e916d3d28
ipynb
Jupyter Notebook
cw04-primes.ipynb
chapman-phys220-2018f/cw04-thepenguins
42b2f87b1d67ebd4f5f8868c7eb7eb2cc286e1e5
MIT
cw04-primes.ipynb
chapman-phys220-2018f/cw04-thepenguins
42b2f87b1d67ebd4f5f8868c7eb7eb2cc286e1e5
MIT
cw04-primes.ipynb
chapman-phys220-2018f/cw04-thepenguins
42b2f87b1d67ebd4f5f8868c7eb7eb2cc286e1e5
MIT
Qwen/Qwen-72B
1. YES
2. YES