I am trying to solve this programming puzzle:
You are given a positive integer N (0 <N <10). Your task is to print a palindromic triangle of size N.
For example, a palindromic triangle of size 5:
1
121
12321
1234321
123454321
You cannot take more than two lines. You must execute the code using only one print statement.
Note. Using anything related to strings will give a score of 0. Using more than one for-statement will give a score of 0.
I can only think of a “dumb” way to do this:
for i in range(1, N+1):
print([0, 1, 121, 12321, 1234321, 123454321, 12345654321, 1234567654321, 123456787654321, 12345678987654321][i])
Is there a more elegant solution?
source
share