Law of cosines - triples: Difference between revisions
m
→{{header|Haskell}}: (minor tidying)
(→{{header|zkl}}: added code) |
m (→{{header|Haskell}}: (minor tidying)) |
||
Line 262:
import Control.Arrow (second)
--triplesFound :: Int -> [(Int, [(Int, Int)])]
triplesFound n =
let xs = ((,) <*> (^ 2)) <$> [1 .. n] :: [(Int, Int)]
Line 273:
let d = snd z - (snd x + snd y)
in if 0 == d
then [(90, fst <$> [x, y, z])]
else if (fst x * fst y) == abs d
then if 0 < d
then [(60, fst <$> [x, y, z])]
else [(120, fst <$> [x, y, z])]
else []
showTriples :: [(Int, [
showTriples xs =
unlines $
zipWith
(\
▲ show (length vs) <> " solutions for " <> show n <> " degrees:\n" <>
["60", "90", "120"]
(nub .
groupBy (on (==) fst) (
▲ groupBy (on (==) fst) (second (fmap fst) <$> sortBy (comparing fst) xs)
main :: IO ()
|