DEV Community

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

Collapse
 
cipharius profile image
Valts Liepiņš

Haskell

import Data.Ratio (numerator, denominator)

side_len :: Int -> Int -> [Int]
side_len a b
  | cd == 1   = [b'-a'+1 .. c'-1] <> [c'+1 .. a'+b'-1]
  | otherwise = [b'-a'+1 .. a'+b'-1]
  where
    a' = a `min` b
    b' = a `max` b
    c  = toRational $ sqrt $ fromIntegral $ a^2 + b^2
    c' = fromIntegral $ numerator c
    cd = fromIntegral $ denominator c