Skip to content

Instantly share code, notes, and snippets.

@sbp
Created June 28, 2010 12:19
Show Gist options
  • Save sbp/455767 to your computer and use it in GitHub Desktop.
Save sbp/455767 to your computer and use it in GitHub Desktop.
common = 74
results = []
# following function from http://bit.ly/ftnW6
def factor(n):
if n == 1: return [1]
i = 2
limit = n**0.5
while i <= limit:
if n % i == 0:
ret = factor(n/i)
ret.append(i)
return ret
i += 1
return [n]
for i in xrange(500):
factors = factor(i)
diffs = [(abs(common - f), f) for f in factors]
minimum = min(diffs)
results.append(common - minimum[1])
print ','.join(str(res) for res in results)
print
results = []
for i in xrange(500):
factors = factor(i)
diffs = [(abs(common - f), f) for f in factors]
minimum = min(diffs)
results.append(abs(common - minimum[1]))
print ','.join(str(res) for res in results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment