Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List (nubBy)
- -- SOLUTION 1
- friends xs = nubBy f [(a, b) | a <- xs, b <- xs, ((a + b) `mod` 10) == 0]
- where
- f (a1, b1) (a2, b2) = (a1 == b2) && (a2 == b1)
- main :: IO()
- main = do
- a <- (readLn :: IO [Int])
- let frs = friends a
- putStrLn $ "Ha " ++ (show $ length frs) ++ " pares:"
- mapM_ putStrLn $ map show frs
- -- SOLUTION 2 (related)
- import Control.Monad (guard)
- import Data.List (nubBy)
- friends xs = do
- a <- xs
- b <- xs
- guard $ (a + b) `mod` 10 == 0
- return $ (a, b)
- main :: IO()
- main = do
- a <- (readLn :: IO [Int])
- let frs = nubBy f $ friends a
- putStrLn $ "Ha " ++ (show $ length frs) ++ " pares:"
- mapM_ putStrLn $ map show frs
- where
- f (a1, b1) (a2, b2) = (a1 == b2) && (a2 == b1)
Advertisement
Add Comment
Please, Sign In to add comment