Skip to content

Commit cb27764

Browse files
authored
To print a no. as sum of no.s in binary form I.e. palindrome
1 parent 31d6fd4 commit cb27764

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

PalSum.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def ok(num, arr):
2+
for i in range(num-1,-1,-1):
3+
if(arr[i]==1):
4+
return i+1
5+
6+
arr = [0 for i in range(1000)]
7+
for i in range(1,1001):
8+
st = str(bin(i)).replace("0b","")
9+
if(st[::-1]==st):
10+
arr[i-1]=1
11+
12+
T = int(input())
13+
for i in range(T):
14+
N = int(input())
15+
ans=[]
16+
while(N>0):
17+
num = ok(N,arr)
18+
ans.append(num)
19+
N-=num
20+
print(len(ans))
21+
print(*ans, sep = " ")

0 commit comments

Comments
 (0)