2025-12-14 Short Review
Five questions. Nothing tricky. Less than 40 minutes.
-
Remove all the repetitions. Keep numbers in the order you find them.
norep :: [Int] -> [Int] norep [1,1,1,2,1,2,2,2,3,4,3] == [1,2,3,4] -
Count the repetitions.
cr :: [String] -> [(String,Int)] cr ["a","b","b","b","a"] == [("a",2),("b",3)] -
Given a string and a list of letters, replace every letter not in the list of letters with a underscore
'_'.cross :: String -> [Char] -> String cross "Wombat" "ao" == "_o__a_" -
Find the total y coordinates of every pair for which the selection function returns true when run on x.
cwan :: (String->Bool) -> [(String,Int)] -> Int(a) use recursion (b) use some higher order function (map, filter, fold, lambda) in addition to some built-in function(s)
-
Is this an efficient way to add up the corresponding product of the first n term in two lists? Comment/fix.
f n xs ys = helper 0 where helper k | k < n = xs!!k * ys!!k + helper (k+1) | otherwise = 0 -
Next year I’m going to teach
>>=withMaybeff n | even n = Just (n*5) | otherwise = Nothing [Just 5, Nothing, Just 8] >>= ff == [Just 40]Anyway, you know enough to write the function
>>=now. Try it.