Project Euler #206: Concealed Square

Sort by

recency

|

42 Discussions

|

  • + 0 comments

    Yeah can't get past the 16th case (python3) :(

    import math
    
    def replacements(c):
        allRepl = []
        pot = (10)**c
        for i in range(0, pot):
            allRepl.append(str(i).zfill(c))
        return allRepl
    
    def allNums(s, r):
        for i in r:
            strin = ""
            count = 0
            strin += s[count]
            for letter in i:
                count += 1
                strin += letter
                strin += s[count]
            if(math.sqrt(int(strin)) == int(math.sqrt(int(strin)))):
                return int(math.sqrt(int(strin)))
        
    knownNums = input()
    numsString = input().rstrip().split()
    
    c = int(knownNums)-1
    print(allNums(numsString, replacements(c)))
    
  • + 0 comments

    Passed only 16 cases...Time limit exceeded :/

    and it is marked as "Easy" ಥ_ಥ

    import itertools
    n = int(input())
    fuc = 0
    s = list(map(int, input().split()))
    flag = 0
    res = [0]*(2*n-1)
    for i in range(0, 2 * n, 2):
        res[i] = s[flag]
        flag = flag+1
    for i in itertools.count(start=10):
        fuc = (i*i)
        square = list(map(int, str(fuc)))
        if (res[::2] == square[::2]):
            print(i)
            break
    
  • + 0 comments

    n=int(input()) q=input() q1=q.split(" ") x="" for q2 in q1: x=x+q2 a1=list(x) s="" l=len(a1) for i in range((10(l-1)),(10l)): sq=1 s="" sq1=[] sq=i*i sq1=list(str(sq)) for j in range(0,(len(sq1)),2): s=s+sq1[j] if s == x: print(i) break**

    My solution passed 16 test cases only. Rest all the cases aborted due to timeout. Any suggestions to reduce calculation time. My code is in python.

  • + 0 comments

    Enter your code here. Read input from STDIN. Print output to STDOUT

    n=int(input()) p=str(input()) lst=p.split() num=('').join(p.split()) d=lst[0] e=lst[0] for l in lst[1:]: d+='0'+l e+='9'+l a=int(d)**0.5 b=int(e)**0.5 for z in range(int(a),int(b)+1): k=(z**2) k=str(k) if k[::2]==num: print(z) break break

  • + 1 comment

    can anyone tell me how to reduce the looping to generate the expected square root. for me only 17 test cases are passed