From 18a639eb460d7581a5dd594a50eb236ae7675685 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Tue, 17 Mar 2015 14:33:20 +0800 Subject: +16 +17 +18 +19 --- h16.hs | 2 ++ h17.hs | 10 ++++++++++ h18.hs | 7 +++++++ h19.hs | 6 ++++++ 4 files changed, 25 insertions(+) create mode 100644 h16.hs create mode 100644 h17.hs create mode 100644 h18.hs create mode 100644 h19.hs diff --git a/h16.hs b/h16.hs new file mode 100644 index 0000000..68978a7 --- /dev/null +++ b/h16.hs @@ -0,0 +1,2 @@ +dropEvery :: [a] -> Int -> [a] +dropEvery xs c = [x| (x,y) <- (zip xs [1..]), y `mod` c /= 0 ] diff --git a/h17.hs b/h17.hs new file mode 100644 index 0000000..fa26f35 --- /dev/null +++ b/h17.hs @@ -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) diff --git a/h18.hs b/h18.hs new file mode 100644 index 0000000..b9e8192 --- /dev/null +++ b/h18.hs @@ -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] diff --git a/h19.hs b/h19.hs new file mode 100644 index 0000000..45c5a07 --- /dev/null +++ b/h19.hs @@ -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 -- cgit v1.2.3-70-g09d2