Skip to content

Instantly share code, notes, and snippets.

@DJMcMayhem
Created June 5, 2016 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DJMcMayhem/e4501fae1be88f45e5b3dceea69b36f9 to your computer and use it in GitHub Desktop.
Save DJMcMayhem/e4501fae1be88f45e5b3dceea69b36f9 to your computer and use it in GitHub Desktop.
from math import ceil as c
def best_score(n):
score = lambda l:abs(l[1]-l[0])+(l[0]*l[1]-n)
possible = []
for i in range(1,n+1):
possible.append((i, c(n/i)))
return min(possible, key=score)
for i in range(1, 100):
print("{}:\t{}".format(i, best_score(i)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment