Created
May 15, 2014 21:43
-
-
Save lorenmh/467d465777dd26a55741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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