Triangle Quest 2

  • + 0 comments

    My first solution was

    print("".join(["".join([str(x) for x in range(1,i)]),str(i),"".join([str(y) for y in range(i-1,0,-1)])]))
    

    After, I was hit with the hidden constraint cant use str(). So I went with

    print(sum([x * 10**((1 + (i - 1)*2)-x) + x * 10**(x-1) for x in range(1,i)]) + i * 10**(i-1))
    

    And that returned “you can only use one for loop” …. 😡 But the posted solution

    print((10 ** i // 9) ** 2)
    

    Is really elegant so I’m glad to have come to this discussion page.