DEV Community

Discussion on: Daily Challenge #218 - Possible Sides of a Non-Right Triangle

Collapse
 
vidit1999 profile image
Vidit Sarkar

Here is a Python one liner,

side_len = lambda a, b: [c for c in range(abs(b-a) + 1, b+a) if not (lambda arr: arr[0] + arr[1] == arr[2])(sorted([a*a, b*b, c*c]))]

And here is the detailed version of above,

def checkPythagorean(a: int, b: int, c: int) -> bool:
    arr = sorted([a*a, b*b, c*c])
    return arr[0] + arr[1] == arr[2]

def side_len(a: int , b: int) -> list:
    lst = []
    for c in range(abs(b-a)+1, b+a):
        if not checkPythagorean(a, b, c):
            lst.append(c)
    return lst

Outputs

print(side_len(1, 1)) # output -> [1]
print(side_len(3, 4)) # output -> [2, 3, 4, 6]
print(side_len(4, 6)) # output -> [3, 4, 5, 6, 7, 8, 9]
print(side_len(5, 12)) # output -> [8, 9, 10, 11, 12, 14, 15, 16]
print(side_len(8, 10)) # output -> [3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]