Created
July 25, 2017 11:48
-
-
Save DomNomNom/7e5d20cae63a3fa63164e9081bfbdc16 to your computer and use it in GitHub Desktop.
Twice as shifty
This file contains hidden or 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
# Find a number n which is_twice_as_shifty(n) | |
def is_twice_as_shifty(n): | |
n = int(n) | |
if n < 1: | |
return False | |
n_str = str(n) | |
n_times_two_str = n_str[-1] + n_str[:-1] # Shift the digits around | |
n_times_two = int(n_times_two_str) | |
difference = n_times_two - n*2 # Tadaa! It should've doubled | |
if difference: | |
print ('You missed by {}'.format(abs(difference))) | |
return False | |
return True | |
# Close, but no cigar | |
print (is_twice_as_shifty(25)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment