Skip to content

Instantly share code, notes, and snippets.

@lorenmh
Created May 15, 2014 21:43
Show Gist options
  • Save lorenmh/467d465777dd26a55741 to your computer and use it in GitHub Desktop.
Save lorenmh/467d465777dd26a55741 to your computer and use it in GitHub Desktop.
def nearest_square_tuple(val):
nearest_sqrt = int(round(math.sqrt(val)))
nearest_square = nearest_sqrt ** 2
return (nearest_sqrt, nearest_square)
def delta_square_to_val(val, square):
delta = val - square
return delta
def square_decrement_tuple(val):
root, square = nearest_square_tuple(val)
if root > 3:
return (square_decrement_tuple(root), delta_square_to_val(val, square))
else:
return (root, delta_square_to_val(val, square))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment