Skip to content

Instantly share code, notes, and snippets.

@SMoni
Created December 26, 2022 13:49
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 SMoni/0273962c9e11c7f23716a8223f5849f5 to your computer and use it in GitHub Desktop.
Save SMoni/0273962c9e11c7f23716a8223f5849f5 to your computer and use it in GitHub Desktop.
What will this method do...
def do_magic(decimal_num:int):
if decimal_num < 2:
return decimal_num
result = 0
square_num = 2
while square_num < decimal_num:
square_num *= 2
while square_num > .5:
result *= 10
if decimal_num >= square_num:
decimal_num -= square_num
result += 1
square_num /= 2
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment