We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Please help me, I got wrong answer for every test case, but I don't know what is wrong with my solution. Below is my algorithm to check whether there is any 1 solution or not:
def CalculateSol(L):
max = L/4
sol = []
for a in xrange(1,max+1):
b = (L*L-2*L*a)/float(2*(L-a))
if math.floor(b)==b:
# b is integer solution
b = int(b)
if a*a+b*b==(L-a-b)*(L-a-b):
# a and b satisfy pythagoras theorem
sol.append([a,b,L-a-b])
if len(sol)>1:
# if solution is already more than 1
return -1
if len(sol)==1:
# Solution exactly 1
return L
else:
return -1
def Main(N):
count = 0
for L in xrange(12,N+1):
if CalculateSol(L)>-1:
print L
count+=1
print count
def input():
T = int(raw_input(""))
for i in xrange(0,T):
N = int(raw_input(""))
Main(N)
I manually check this function and as far as I know this return correct answer. Which case do you think this algorithm fail to calculate? I know this is slow, but I wil think about it after this gives corect result.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #75: Singular integer right triangles
You are viewing a single comment's thread. Return to all comments →
Please help me, I got wrong answer for every test case, but I don't know what is wrong with my solution. Below is my algorithm to check whether there is any 1 solution or not:
I manually check this function and as far as I know this return correct answer. Which case do you think this algorithm fail to calculate? I know this is slow, but I wil think about it after this gives corect result.