summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--11-20/14.hs4
-rw-r--r--11-20/15.hs7
-rw-r--r--11-20/16.hs7
-rw-r--r--11-20/17.hs6
-rw-r--r--11-20/18.hs6
-rw-r--r--11-20/19.hs6
-rw-r--r--11-20/20.hs6
7 files changed, 42 insertions, 0 deletions
diff --git a/11-20/14.hs b/11-20/14.hs
new file mode 100644
index 0000000..6071891
--- /dev/null
+++ b/11-20/14.hs
@@ -0,0 +1,4 @@
+dupli :: [a] -> [a]
+
+dupli [] = []
+dupli (x:xs) = x:x:(dupli xs)
diff --git a/11-20/15.hs b/11-20/15.hs
new file mode 100644
index 0000000..f11d61c
--- /dev/null
+++ b/11-20/15.hs
@@ -0,0 +1,7 @@
+repli :: [a] -> Int -> [a]
+
+repli l n = rep l n
+ where rep [] i = []
+ rep (x:xs) i
+ | i > 0 = x:(rep (x:xs) (i - 1))
+ | otherwise = rep xs n
diff --git a/11-20/16.hs b/11-20/16.hs
new file mode 100644
index 0000000..74cc946
--- /dev/null
+++ b/11-20/16.hs
@@ -0,0 +1,7 @@
+dropEvery :: [a] -> Int -> [a]
+
+dropEvery l n = d l 1
+ where d [] i = []
+ d (x:xs) i
+ | i == n = d xs 1
+ | otherwise = x:d xs (i + 1)
diff --git a/11-20/17.hs b/11-20/17.hs
new file mode 100644
index 0000000..e058b27
--- /dev/null
+++ b/11-20/17.hs
@@ -0,0 +1,6 @@
+split :: [a] -> Int -> ([a], [a])
+
+split [] _ = ([], [])
+split l@(x:xs) n
+ | n > 0 = let (ys, zs) = split xs (n - 1) in (x:ys, zs)
+ | otherwise = ([], l)
diff --git a/11-20/18.hs b/11-20/18.hs
new file mode 100644
index 0000000..e2ec1fb
--- /dev/null
+++ b/11-20/18.hs
@@ -0,0 +1,6 @@
+slice :: [a] -> Int -> Int -> [a]
+
+slice (x:xs) n m
+ | n > 1 = slice xs (n - 1) (m - 1)
+ | m > 0 = x:slice xs 0 (m - 1)
+slice _ _ _ = []
diff --git a/11-20/19.hs b/11-20/19.hs
new file mode 100644
index 0000000..f1e795b
--- /dev/null
+++ b/11-20/19.hs
@@ -0,0 +1,6 @@
+rotate :: [a] -> Int -> [a]
+
+rotate l n = let (a, b) = rot l (if n < 0 then (n + length l) else n) in b ++ a
+ where rot l@(x:xs) n
+ | n > 0 = let (a, b) = rot xs (n - 1) in (x:a, b)
+ | otherwise = ([], l)
diff --git a/11-20/20.hs b/11-20/20.hs
new file mode 100644
index 0000000..c6a3ba8
--- /dev/null
+++ b/11-20/20.hs
@@ -0,0 +1,6 @@
+removeAt :: Int -> [a] -> (Maybe a, [a])
+
+removeAt k (x:xs)
+ | k > 1 = let (a, b) = removeAt (k - 1) xs in (a, x:b)
+ | k == 1 = (Just x, xs)
+removeAt _ l = (Nothing, l)