Created
June 9, 2016 01:57
-
-
Save dmp1ce/5fbbb2e7f49d210849531c504f009a02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--skipAt :: Int -> [a] -> [[a]] | |
--skipAt n (x:xs) | |
-- | length xs > n = [[x]] ++ (skipAt n xs) | |
-- | length xs <= n = [[x]] | |
-- | n < 0 = [(x:xs)] | |
-- | otherwise = skipAt (n-1) xs | |
-- Working solution | |
skipAt :: Int -> [a] -> [[a]] | |
skipAt n ls | |
| n <= 0 = [ls] | |
| otherwise = skipAt' n ls | |
where | |
skipAt' :: Int -> [a] -> [[a]] | |
skipAt' 0 (x:xs) | |
| length xs > n = [[x]] ++ (skipAt' n xs) | |
| length xs <= n = [[x]] | |
skipAt' m (x:xs) = skipAt' (m-1) xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment