Commits

Anonymous committed 29ed6da

Problems 16 (corrected), 18 and 19

Comments (0)

Files changed (1)

 
 -- 16
 dropEvery :: [a] -> Int -> [a]
-dropEvery xs n = take (n-1) xs : dropEvery (drop n xs) n
+dropEvery [] _ = []
+dropEvery xs n = take (n-1) xs ++ dropEvery (drop n xs) n
+
+-- 17
+split :: [a] -> Int -> ([a], [a])
+-- split xs n = (take n xs, drop n xs) -- Uses predefined predicates
+split xs 0 = ([], xs)
+split (x:xs) n = let (f,l) = split xs (n-1) in (x : f, l)
+
+-- 18
+slice :: [a] -> Int -> Int -> [a]
+slice xs n m = take (m-n+1) $ drop (n-1) xs