themoosemind

http://math.stackexchange.com/q/882865/6876

Jul 30th, 2014
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. def digit_reverse(N):
  5.     return int(str(N)[::-1])
  6.  
  7.  
  8. def test(N, n):
  9.     """ Test if a = (N digit-reversed) fulfils n*N = a """
  10.     return n*N == digit_reverse(N)
  11.  
  12.  
  13. def search_smallest(n):
  14.     # Obiously, it works for 0...
  15.     N = 1
  16.     while not test(N, n):
  17.         N += 1
  18.     return N
  19.  
  20. if __name__ == '__main__':
  21.     from argparse import ArgumentParser
  22.  
  23.     parser = ArgumentParser()
  24.  
  25.     # Add more options if you like
  26.     parser.add_argument("-n", "--multiplier", dest="n", default="9", type=int)
  27.     args = parser.parse_args()
  28.     print(search_smallest(args.n))
Add Comment
Please, Sign In to add comment