Skip to content

Instantly share code, notes, and snippets.

@CarloMicieli
Created July 13, 2014 15:55
Show Gist options
  • Save CarloMicieli/e5436a3f2a0cfca5be58 to your computer and use it in GitHub Desktop.
Save CarloMicieli/e5436a3f2a0cfca5be58 to your computer and use it in GitHub Desktop.
twoLargest :: (Num a, Ord a) => a -> a -> a -> (a, a)
twoLargest x y z
| x <= y && x <= z = (y, z)
| y <= x && y <= z = (x, z)
| otherwise = (x, y)
square :: (Num a) => a -> a
square x = x * x
squarePair :: (Num a) => (a, a) -> (a, a)
squarePair (f, s) = (square f, square s)
sumPair :: (Num a) => (a, a) -> a
sumPair (f, s) = f + s
sumSquareTwoLargest :: (Num a, Ord a) => a -> a -> a -> a
sumSquareTwoLargest x y z = sumPair $ squarePair $ twoLargest x y z
secondLargest :: (Num a, Ord a) => a -> a -> a -> a
secondLargest x y z = min (fst p) (snd p)
where p = twoLargest x y z
p :: Int -> Int
p x = p x
test :: Int -> (Int -> Int) -> Int
test x y = if x == 0 then 0 else (y x)
max3 :: (Num a, Ord a) => a -> a -> a -> a
max3 x y z
| x >= y && x >= z = x
| y >= x && y >= z = y
| otherwise = z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment