Header Ad

HackerRank Triangle Quest 2 solution in python

In this Triangle Quest 2 problem, we need to develop a python program that can read an integer input and then print a triangle equal to the size of that input on the output screen.

HackerRank Triangle Quest 2 solution in python


Problem solution in Python 2 programming.

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 sum(map(sum, map(lambda y: map(lambda x: 10 ** x, xrange(y)), xrange(1, i + 1)))) * (10 ** (i-1))+sum(map(sum, map(lambda y: map(lambda x: 10 ** (i - x - 2), xrange(y)), xrange(1, i))))


Problem solution in Python 3 programming.

for i in range(1,int(input())+1): #More than 2 lines will result in 0 score. Do not leave a blank line also
    print (((10**i - 1)//9)**2)


Problem solution in pypy programming.

for x in range(1,int(input())+1):
    print(((10**x - 1)//9)**2)


Problem solution in pypy3 programming.

for x in range(1,int(input())+1):# Enter your code here. Read input from STDIN. Print output to STDOUT
    print(((111111111)%(10**x))**2)


Post a Comment

0 Comments