{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} {-# HLINT ignore "Avoid reverse" #-} {-# HLINT ignore "Use void" #-} import Data.Char (toUpper) import Data.List (isSuffixOf, sort, sortOn) import Test.HUnit names = ["Oliver", "Emma", "Liam", "Ava", "Noah", "Sophia", "James", "Mia", "Elijah", "Isabella"] ages = [25, 30, 22, 29, 35, 28, 40, 26, 33, 31] -- we are looking for the UPPERCASE names of the two oldest persons whose names ends with an a sorted alphabetically" names2 = map (map toUpper) names kombi = zip names2 ages endetAufA kombi = filter (\(str, _) -> not (null str) && last str == 'A') kombi oldest = sortOn (negate . snd) (endetAufA kombi) extractedNames = sort $ map fst $ take 2 oldest test1 = Test.HUnit.TestCase (assertEqual "ExtractedNames" ["EMMA", "ISABELLA"] extractedNames) tests = TestList [test1] istPrim :: Int -> Bool istPrim n | n < 2 = False | otherwise = null [x | x <- [2 .. isqrt n], n `mod` x == 0] where isqrt = floor . sqrt . fromIntegral prime :: Int -> [Int] prime x = [n | n <- [2 .. x], istPrim n] main :: IO () main = runTestTT test1 >> return ()