Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import time
- starttime = time.time()
- def reverse(a):
- return int(str(a)[::-1])
- def is_all_odd_digits(a):
- for x in str(a):
- if x not in "13579":
- return False
- return True
- total_cnt = 0
- odd_digits = set(['1','3','5','7','9'])
- #dont need to do for 9 digits
- for no_digits in range(2,9):
- low = 10**(no_digits-1)+1
- mid = 10**no_digits/2
- cnt = 0
- try:
- for x in xrange(low,mid):
- if x%10 != 0:
- x_str = str(x)
- if int(x_str[0])%2 != int(x_str[-1])%2:
- s = x+int(x_str[::-1])
- cnt += is_all_odd_digits(s)
- print no_digits, cnt
- total_cnt += cnt*2
- print total_cnt
- print "Took %ss" % (time.time()-starttime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement