H-99: Ninety-Nine Haskell Problems
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
These are Haskell translations of Ninety Nine Lisp Problems.
Problem 1
(*) Find the last box of a list. Example: * (my-last '(a b c d)) (D)
This is "last" in Prelude, which is defined as:
last :: [a] -> a
last [x] = x
last (_:xs) = last xs
Problem 2
(*) Find the last but one box of a list. Example: * (my-but-last '(a b c d)) (C D)
This can be done by dropping all but the last two elements of a list:
myButLast :: [a] -> [a]
myButLast list = drop ((length list) - 2) list