CPS506 Lab 5 Haskell: Functions & type signatures
In the provided source file called Lab5.hs you will implement each of the functions described below. All functions written for this lab must be placed in this single module. Make sure each of your functions is named precisely according to the specifications below, and the type signature is not modified in any way. You can test your code by running ‘cabal test’ from the lab5 directory (same idea as an Elixir mix project)
STEP BY STEP ANSWER WITH EXPLANATION
Below is the explanation for the implementations for each function described in the lab:
1. third_last :: [a] -> a
2. every_other :: [a] -> [a]
every_other :: [a] -> [a]
every_other [] = []
3. is_cyclops :: Int -> Bool
is_cyclops n = let s = show n
len = length s
4. domino_cycle :: [(Int, Int)] -> Bool
domino_cycle [] = True
domino_cycle ds = all (uncurry (==)) (zip (map snd ds) (map fst (tail ds ++ [head ds])))
5. tukeys_ninther :: (Ord a, Num a) => [a] -> a
medianOfThree xs = sort xs !! 1
tukeys_ninther :: (Ord a, Num a) => [a] -> a
chunksOf _ [] = []
chunksOf n xs = take n xs : chunksOf n (drop n xs)