-- 5
extractOddsNoListComp :: [Int] -> [Int]
extractOddsNoListComp [] = []
extractOddsNoListComp (x:xs)
    | odd x     = x : extractOddsNoListComp xs
    | otherwise = extractOddsNoListComp xs

extractOddsListComp :: [Int] -> [Int]
extractOddsListComp xs = [ x | x <- xs, odd x ]

-- 7.6
elemNumNoListComp :: Int -> [Int] -> Int
elemNumNoListComp a [] = 0
elemNumNoListComp a (x:xs)
    | a == x    = 1 + elemNumNoListComp a xs
    | otherwise = elemNumNoListComp a xs

elemNumListComp :: Int -> [Int] -> Int
elemNumListComp a xs = length [ x | x <- xs, a == x ]

-- 7.11
insDesc :: Int ->  [Int] -> [Int]
insDesc x []       = [x]
insDesc x (y:ys)
  | x >= y     = x:y:ys
  | otherwise  = y : insDesc x ys

iSortDesc :: [Int] -> [Int]
iSortDesc []     = []
iSortDesc (x:xs) = insDesc x (iSortDesc xs)

insAscRmDup :: Int ->  [Int] -> [Int]
insAscRmDup x []       = [x]
insAscRmDup x (y:ys)
  | x < y     = x:y:ys
  | x == y    = y:ys
  | otherwise = y : insAscRmDup x ys

iSortAscRmDup :: [Int] -> [Int]
iSortAscRmDup []     = []
iSortAscRmDup (x:xs) = insAscRmDup x (iSortAscRmDup xs)

-- 7
dropList :: Int -> [t] -> [t]
dropList x [] = []
dropList 0 xs  = xs
dropList x (y:xs) = dropList (x - 1) xs

-- 7.7
uniqueListComp :: [Int] -> [Int]
uniqueListComp xs = [ x | x <- xs, elemNumListComp x xs == 1 ]

