Skip to content

Instantly share code, notes, and snippets.

@PeterJCLaw
Created June 30, 2011 18:26
Show Gist options
  • Save PeterJCLaw/1056854 to your computer and use it in GitHub Desktop.
Save PeterJCLaw/1056854 to your computer and use it in GitHub Desktop.
import prime
def find(i):
# odd numbers
if i % 2 == 1:
return (i-1)/2, 2
# divides by a prime
for pn in range(2, 1001):
# skip 2 - even ones don't work like this.
if pn % 2 == 0:
continue
if i % pn == 0:
return (i/pn) - (pn - 1)/2, pn
return 1,1
def getNumbers(bottom, count):
numbers = []
assert count != 0
for i in range(bottom, bottom+count):
numbers.append(i)
return numbers
if __name__ == '__main__':
for i in range(1000, 2001):
bottom, count = find(i)
numbers = getNumbers(bottom, count)
actualSum = sum(numbers)
if i % 50 == 0:
print i
if actualSum != i:
print 'fail', i, 'gave', actualSum, 'from', numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment