Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import math
  2. import time
  3.  
  4. starttime = time.time()
  5. def reverse(a):
  6.     return int(str(a)[::-1])
  7.  
  8. def is_all_odd_digits(a):
  9.     for x in str(a):
  10.         if x not in "13579":
  11.             return False
  12.     return True
  13.  
  14. total_cnt = 0
  15. odd_digits = set(['1','3','5','7','9'])
  16.  
  17. #dont need to do for 9 digits
  18. for no_digits in range(2,9):
  19.     low = 10**(no_digits-1)+1
  20.     mid = 10**no_digits/2
  21.     cnt = 0
  22.     try:
  23.         for x in xrange(low,mid):
  24.             if x%10 != 0:
  25.                 x_str = str(x)
  26.                 if int(x_str[0])%2 != int(x_str[-1])%2:
  27.                     s = x+int(x_str[::-1])
  28.                     cnt += is_all_odd_digits(s)
  29.         print no_digits, cnt
  30.     total_cnt += cnt*2
  31.  
  32. print total_cnt
  33. print "Took %ss" % (time.time()-starttime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement