Triangle Quest 2

Sort by

recency

|

1184 Discussions

|

  • + 0 comments

    WTF? How is this a programming problem?

  • + 0 comments

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

  • + 0 comments

    As in the first Triangle Quest, I had no idea this was a known math problem and I went a little crazy

        print(pow(sum(list(map(pow,[10]*i,range(i-1,-1,-1)))),2))
    

    I figured this out

    # 1 -> 1 = 1 * 1 = (10**0)**2
    # 2 -> 121 = 11 * 11 = (10**1 + 10**0)**2
    # 3 -> 12321 = 111 * 111 = (10**2 + 10**1 + 10**0)**2
    # 4 -> 1234321 = 1111 * 1111 = ...
    # 5 -> 123454321 = 11111 * 11111
    

    So I tried to build the sum of the powers of ten to power it by 2 after:

    • [10]*i get's you a list of i 10s
    • range(i-1,-1,-1) get's you an iterator of the powers from i-1 to 0
    • map(pow,[10]*i,range(i-1,-1,-1)) will get you an iterator that powers each 10 to each value - given by range() in the same position
    • list(...) of the latter result will get you a proper list that you can sum(...)
    • and you finish by powering it by 2

    Or you can just print(((10**i-1)//9)**2) gives the same thing

  • + 0 comments

    This is not really a test of python skills... this is just a math problem. What is the point for someone who is trying to brush up on python?

  • + 0 comments

    Looking at the math based solutions, now I understand why there was that strange limit at input below 10. Of course, this method does not work above 10.

    Now: find a method which still work above 10 :-)