• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Mar 31st, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def is_palindrome(base,n):
2.     if n % base == 0:
3.         return False
4.     front = n
5.     back = 0
6.     while back < front:
7.         d = front % base
8.         front = front // base
9.         if back == front:
10.             return True
11.         back = back * base + d
12.     return front == back
13.
14. def revert(base,n):
15.     r = 0
16.     while n > 0:
17.         d = n % base
18.         n = n // base
19.         r = r * base + d
20.     return r
21.
22. def make_palindromes(base,d):
23.     low = base ** (d-1)
24.     high = low * base
25.     for n in xrange(low, high):
26.         b = revert(base,n)
27.         for a in xrange(base):
28.             yield ((n * base + a)*high + b)
29.
30. def digit_list(base,n):
31.     if n == 0:
32.         return [0]
33.     dl = []
34.     while n > 0:
35.         dl.append(n % base)
36.         n = n // base
37.     return dl
38.
39. b = 113
40. d = 3
41.
42. for p in make_palindromes(b,d):
43.     if is_palindrome(b+2,p):
44.         print p, digit_list(b,p), digit_list(b+2,p)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top