You are given a positive integer .
Your task is to print a palindromic triangle of size .
Your task is to print a palindromic triangle of size .
For example, a palindromic triangle of size is:
1
121
12321
1234321
123454321
You can't take more than two lines. The first line (a for-statement) is already written for you.
You have to complete the code using exactly one print statement.
You have to complete the code using exactly one print statement.
Note:
Using anything related to strings will give a score of .
Using more than one for-statement will give a score of .
Using anything related to strings will give a score of .
Using more than one for-statement will give a score of .
Input Format
A single line of input containing the integer .
Constraints
Output Format
Print the palindromic triangle of size as explained above.
Sample Input
5
Sample Output
1
121
12321
1234321
123454321
Triangle Quest 2 - Hacker Rank Solution
It is interesting to note that for integers greater than 0 and less than 10.
and
Set by
DOSHI
Problem Setter's code:
for i in xrange(1,int(raw_input())+1):
print (10**i/9)**2
Another Method 01:
for i in range(1,int(raw_input())+1): #More than 2 lines will result in 0 score. Do not leave a blank line also
print reduce(lambda x, y: x + (10 ** (y - 1)), range(1, i + 1))**2
Another Method 02:
for i in range(1,int(raw_input())+1): #More than 2 lines will result in 0 score. Do not leave a blank line also
print [1, 121, 12321, 1234321, 123454321, 12345654321,1234567654321, 123456787654321, 12345678987654321][i-1]
Thankyou so much...Your explanations helps us to understand the problem easily
ReplyDeletefor i in range(1,int(input())+1):
ReplyDeleteprint((10**i//9)**2 )
THANKS SOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO MUCHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
ReplyDeleteTHANKS
THANKS
GOD MAY ALWAYS BLEES YOU