Project Euler #210: Obtuse Angled Triangles

Sort by

recency

|

14 Discussions

|

  • + 0 comments

    I am also getting four correct test cases and a timeout on the rest of the cases when I submit the code. This is a little frustrating as I don't think it's something wrong with my code. If anybody has an answer for this it would surely be appreciated!

  • + 0 comments

    4 test cases passed, rest timed out. please send efficient algo

  • + 0 comments

    how to find the point in the s(r)

  • + 0 comments

    can anyone explain what we need to do? i am unable to understand it.

  • + 0 comments
    import math
    r,a,b,n = map(int, input().split())
    count=0
    #function length_sq() for returning square of the side
    def length_sq(tuple,list):
        len = (((list[0]-tuple[0])**2) + ((list[1]-tuple[1])**2))
        return len 
    #Coordinates of Point A
    A=(a/b,a/b)
    #C-ordinates of point B
    B=((2*n-(a/b)),2*n-(a/b))
    #length of AB
    AB2 = length_sq(A,B)
    AB = math.sqrt(AB2)
    
    for i in range(-r,r+1):
        for j in range(-r,r+1):
            if(abs(i)+abs(j)<=r):
                #length of BC
                BC2 = length_sq(B,(i,j))
                BC = math.sqrt(BC2)
                #length of AC
                AC2 = length_sq(A,(i,j))
                AC = math.sqrt(AC2)
                try:
                    alpha = math.acos((AB2+AC2-BC2)/(2*AB*AC))
                    alpha= (alpha*180)/math.pi
                    alpha= round(alpha,0)
                    
                    beta =  math.acos((AB2+BC2-AC2)/(2*AB*BC))
                    beta= (beta*180)/math.pi
                    beta= round(beta,0)
                    
                    gamma = math.acos((BC2+AC2-AB2)/(2*BC*AC))
                    gamma= (gamma*180)/math.pi
                    gamma=round(gamma,0)
    
                    if((180>alpha > 90) or (90<beta<180) or (90<gamma<180) ):
                        count=count+1
                    except ZeroDivisionError:
                    continue
                except ValueError:
                    continue
    print(count)
    

    All the test cases other than the first 4 gives time exceeded.

    what changes should i make?