diff options
-rw-r--r-- | h16.hs | 2 | ||||
-rw-r--r-- | h17.hs | 10 | ||||
-rw-r--r-- | h18.hs | 7 | ||||
-rw-r--r-- | h19.hs | 6 |
4 files changed, 25 insertions, 0 deletions
@@ -0,0 +1,2 @@ +dropEvery :: [a] -> Int -> [a] +dropEvery xs c = [x| (x,y) <- (zip xs [1..]), y `mod` c /= 0 ] @@ -0,0 +1,10 @@ +split :: [a] -> Int -> ([a],[a]) +split xs c = splitHelper [] xs c + where + splitHelper pre nxt 0 = (reverse pre, nxt) + splitHelper pre (x:nxt) c = splitHelper (x:pre) nxt (c-1) + +split' (x:xs) c | c>0 = + let (pre,nxt) = split' xs (c-1) + in (x:pre,nxt) +split' xs _ = ([],xs) @@ -0,0 +1,7 @@ +slice :: [a] -> Int -> Int -> [a] +slice (x:xs) a b + | a > 1 = slice xs (a-1) (b-1) + | a <= 1 && b >= 1 = x:(slice xs (a-1) (b-1)) + | otherwise = [] + +slice' xs i j = [x | (x,k)<- (zip xs [1..j]) , k >= i] @@ -0,0 +1,6 @@ +rotate :: [a] -> Int -> [a] +rotate xs c + | c < 0 = rotate xs (c + (length xs)) + | otherwise = (drop (c `mod` (length xs)) xs ) ++ (take (c `mod` (length xs)) xs) + +rotate' xs c = take (length xs) $ drop (length xs + c) $ cycle xs |