diff options
author | Determinant <[email protected]> | 2017-05-28 20:29:11 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2017-05-28 20:29:11 -0400 |
commit | 9c608c32a9387a1dd1cb045e5822733ad181ccf8 (patch) | |
tree | 9464fd3f8e218c6000783c80e2db7b573c30ea80 /11-20 | |
parent | b2d6f0e28dac922ac4ed5c55f79d0dd38f4765d2 (diff) |
finish vol 2
Diffstat (limited to '11-20')
-rw-r--r-- | 11-20/14.hs | 4 | ||||
-rw-r--r-- | 11-20/15.hs | 7 | ||||
-rw-r--r-- | 11-20/16.hs | 7 | ||||
-rw-r--r-- | 11-20/17.hs | 6 | ||||
-rw-r--r-- | 11-20/18.hs | 6 | ||||
-rw-r--r-- | 11-20/19.hs | 6 | ||||
-rw-r--r-- | 11-20/20.hs | 6 |
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) |