Skip to content

Instantly share code, notes, and snippets.

@arkenidar
Last active July 18, 2018 12:58
Show Gist options
  • Select an option

  • Save arkenidar/249fb90aaa46a381494049bea41606c3 to your computer and use it in GitHub Desktop.

Select an option

Save arkenidar/249fb90aaa46a381494049bea41606c3 to your computer and use it in GitHub Desktop.
Does every Prime Number >= 3 have the property of being obtainable from a summation of prime numbers themselves? e.g. 2+3=5
#https://repl.it/@dariocangialosi/primesassumofprimes-1
def is_prime(n):
prime=True
for i in range(2,n):
if n%i==0:
prime=False
break
return prime
def primes_iterator(start,limit):
for n in range(start,limit):
if is_prime(n):
yield n
def main():
primes=[0, 1, 2]
for n in primes_iterator(3,100):
primes.append(n)
i=primes.index(n)-1
dec=n
add=[]
while True:
if primes[i]<=dec:
dec-=primes[i]
add.append(primes[i])
if dec==0: break
i-=1
add=map(str,add)
print(n,'=','+'.join(add))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment