Skip to content

Instantly share code, notes, and snippets.

@tshddx
Created July 12, 2019 20:41
Show Gist options
  • Save tshddx/8341d1bdbe2f83ed4e2c26bc48faf6b9 to your computer and use it in GitHub Desktop.
Save tshddx/8341d1bdbe2f83ed4e2c26bc48faf6b9 to your computer and use it in GitHub Desktop.
Preferred numbers (Python)
def preferred_numbers(x, precision = 2):
"""
>>> preferred_numbers(2)
[1.0, 3.16]
>>> preferred_numbers(3)
[1.0, 2.15, 4.64]
>>> preferred_numbers(5)
[1.0, 1.58, 2.51, 3.98, 6.31]
>>> preferred_numbers(10)
[1.0, 1.26, 1.58, 2.0, 2.51, 3.16, 3.98, 5.01, 6.31, 7.94]
>>> preferred_numbers(3, 0)
[1.0, 2.0, 5.0]
# Like Euro denominations!
"""
root = 10 ** (1 / x)
return [round(root ** i, precision) for i in range(x)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment