Skip to content

Instantly share code, notes, and snippets.

@DomNomNom
Created July 25, 2017 11:48
Show Gist options
  • Save DomNomNom/7e5d20cae63a3fa63164e9081bfbdc16 to your computer and use it in GitHub Desktop.
Save DomNomNom/7e5d20cae63a3fa63164e9081bfbdc16 to your computer and use it in GitHub Desktop.
Twice as shifty
# 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