Skip to content

Instantly share code, notes, and snippets.

@dmp1ce
Created June 9, 2016 01:57
Show Gist options
  • Save dmp1ce/5fbbb2e7f49d210849531c504f009a02 to your computer and use it in GitHub Desktop.
Save dmp1ce/5fbbb2e7f49d210849531c504f009a02 to your computer and use it in GitHub Desktop.
--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