Skip to content

Instantly share code, notes, and snippets.

@jonnyrobbie
Last active August 8, 2017 13:59
Show Gist options
  • Select an option

  • Save jonnyrobbie/a083ad5b6fa86f09a7fcd40121a65568 to your computer and use it in GitHub Desktop.

Select an option

Save jonnyrobbie/a083ad5b6fa86f09a7fcd40121a65568 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# brute force solution for https://www.youtube.com/watch?v=1lHDCAIsyb8
def reverse(number):
s_number = str(number)
l_number = len(s_number)
return(int(s_number[l_number-1:] + s_number[:l_number-1]))
correct = 105263157894736842 # yeah...that brute force might took longer than I expected :)
print("Correct solution: %i, reversed: %i or doubled: %i." % (correct, reverse(correct), correct*2))
#i = 1 # it was immediately shown that the solution works with i=0 :)
i = 105263157884736842 # if I nudge it a bit towards a solution, it spits out the correct answer in a short time.
try:
while 2*i != reverse(i):
i = i + 1
except KeyboardInterrupt:
print("Keyboard interrupt. Current i: %i" % i)
raise
print("Number %i, reverse %i" % (i, reverse(i)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment