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, [(Int, Int)])] -> String
showTriples xs =
unlines $
zipWith
(\ns vsg ->
show (length vsg) <> " solutions for " <> show ns <> " degrees:\n" <> show g <>
'"\n' :")
show (length vs) <> " solutions for " <> show n <> " degrees:\n" <>
["60", "90", "120"] show vs)$
(nub . [120,fmap 90, 60]snd) <$>
groupBy (on (==) fst) (secondsortBy (fmapcomparing fst) <$> sortBy(fmap (comparingfmap fstsort) xs))
(nub . fmap (sort . snd)) <$>
groupBy (on (==) fst) (second (fmap fst) <$> sortBy (comparing fst) xs)
 
main :: IO ()
9,655

edits