Skip to content

Instantly share code, notes, and snippets.

@yuwash
Created January 16, 2018 10:42
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 yuwash/26588d6288d24d3f544c38797239c571 to your computer and use it in GitHub Desktop.
Save yuwash/26588d6288d24d3f544c38797239c571 to your computer and use it in GitHub Desktop.
Find best fit for Golden Ratio
def get_best(choice=range(1, 1080)):
'''Find best integer fit for the shorter side of Golden Ratio
Best fit has a integer-valued longer side with the smallest error to the real Golden Ratio
:param choice list(int): choioce of integers
>>> get_best()
(1.2018646489717657e-06, 305)
'''
return min((((x*(5**0.5)/2) % 1)/x, x) for x in choice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment