-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCpalindrome.py
74 lines (64 loc) · 1.05 KB
/
Cpalindrome.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 11 14:58:44 2013
@author: remy
"""
def retournL(L):
i = 0
j = len(L) - 1
while i < j:
L[i] , L[j] = L[j] , L[i]
i += 1
j -= 1
#L = [1,2,3,4,5,6]
#print(L)
#retournL(L)
#print(L)
def decomp(n):
p = 1
while p <= n:
p *= 10
p = p // 10
L = []
while p >= 1:
L.append( n // p)
n = n % p
p = p // 10
return L
def comp(L):
v = 0
i = 0
while i < len(L):
v = 10*v + L[i]
i += 1
return v
#print(comp([1,2,3,4,5]))
def retournN(n):
L = decomp(n)
L.reverse()
return comp(L)
def sym(n):
return n + retournN(n)
def delta(n,p):
i = 0
s = retournN(n)
while s != n and i <= p:
n = n + s
s = retournN(n)
i += 1
#print(n)
return i
#print(delta(98,100))
p = 5000
n = 197
d = 0
nmax = 1
dmax = 0
while d <= p and n <= 300 :
if d > dmax:
dmax = d
nmax = n
n += 1
d = delta(n,p)
print(n,nmax,dmax)
#print(sym(12345))