Created
June 30, 2011 18:26
-
-
Save PeterJCLaw/1056854 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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