forked from noelmarkham/learn-you-a-haskell-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-starting-out.hs
56 lines (46 loc) · 2.07 KB
/
02-starting-out.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{-
-Once you've installed Haskell from http://www.haskell.org/platform/, load the interpreter with the command ghci.
-
-You can load (and reload) this file in the interpreter with the command: ":l 2-starting-out.hs"
-
-The first function has been completed as an example. All the other functions are undefined.
-They can be implemented in one line using the material covered in http://learnyouahaskell.com/starting-out
-
-All indices are zero based.
-}
-- Find the penultimate element in list l
penultimate l = last (init l)
-- Find the element at index k in list l
-- For example: "findK 2 [0,0,1,0,0,0]" returns 1
findK k l = undefined
-- Determine if list l is a palindrome
isPalindrome l = undefined
{-
- Duplicate the elements in list xs, for example "duplicate [1,2,3]" would give the list [1,1,2,2,3,3]
- Hint: The "concat [l]" function flattens a list of lists into a single list.
- (You can see the function definition by typing ":t concat" into the interpreter. Perhaps try this with other variables and functions)
-
- For example: concat [[1,2,3],[3,4,5]] returns [1,2,3,3,4,5]
-}
duplicate xs = undefined
{-
- Imitate the functinality of zip
- The function "min x y" returns the lower of values x and y
- For example "ziplike [1,2,3] ['a', 'b', 'c', 'd']" returns [(1,'a'), (2, 'b'), (3, 'c')]
-}
ziplike xs ys = undefined
-- Split a list l at element k into a tuple: The first part up to and including k, the second part after k
-- For example "splitAtIndex 3 [1,1,1,2,2,2]" returns ([1,1,1],[2,2,2])
splitAtIndex k l = undefined
-- Drop the element at index k in list l
-- For example "dropK 3 [0,0,0,1,0,0,0]" returns [0,0,0,0,0,0]
dropK k l = undefined
-- Extract elements between ith and kth element in list l. Including i, but not k
-- For example, "slice 3 6 [0,0,0,1,2,3,0,0,0]" returns [1,2,3]
slice i k l = undefined
-- Insert element x in list l at index k
-- For example, "insertElem 2 5 [0,0,0,0,0,0]" returns [0,0,0,0,0,2,0]
insertElem x k l = undefined
-- Rotate list l n places left.
-- For example, "rotate 2 [1,2,3,4,5]" gives [3,4,5,1,2]
rotate n l = undefined