-
Notifications
You must be signed in to change notification settings - Fork 14
/
INDEX
194 lines (85 loc) · 3.63 KB
/
INDEX
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
Problem 1
Find the last element of a list.
[1 2 3 7 5] -> 5
Problem 2
Find the last but one element of a list.
[1 2 3 7 5] -> 7
Problem 3
Find the K’th element of a list
The first element in the list is number 1.
[1 2 3 7 5] 4 -> 7
Problem 4
Find the number of elements of a list.
[1 2 3 5 7] -> 5
Problem 5
Reverse a list.
[1 2 3 7 5] -> [5 7 3 2 1]
Problem 6
Find out whether a list is a palindrome.
A palindrome can be read forward or backward.
[1 2 3 3 2 1] -> true
Problem 7
Flatten a nested list structure.
Transform a list, possibly holding lists as elements into a `flat’ list by replacing each list with its elements (recursively).
[1 [2 3 [5 7] 3] 1] -> [1 2 3 5 7 3 1]
Problem 8
Eliminate consecutive duplicates of list elements.
If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not be changed.
[1 1 1 2 2 3 1 5 5 3 3] -> [1 2 3 1 5 3]
Problem 09
Pack consecutive duplicates of list elements into sublists.
If a list contains repeated elements they should be placed in separate sublists.
[1 1 1 2 2 3 1 5 5 3 3] -> [[1 1 1] [2 2] [3] [1] [5 5] [3 3]]
Problem 10
Run-length encoding of a list.
Use the result of problem 9 to implement the so-called run-length encoding data compression method. Consecutive duplicates of elements are encoded as terms (N E) where N is the number of duplicates of the element E.
[1 1 1 2 2 3 1 5 5 3 3] -> [(3 1) (2 2) (1 3) (1 1) (2 5) (2 3)]
Problem 11
Modified run-length encoding.
Modify the result of problem 10 in such a way that if an element has no duplicates it is simply copied into the result list. Only elements with duplicates are transferred as (N E) terms.
Problem 12
Decode a run-length encoded list.
Given a run-length code list generated as specified in problem 11. Construct its uncompressed version.
[(3 1) (2 2) 3 1 (2 5) (2 3)] -> [1 1 1 2 2 3 1 5 5 3 3]
Problem 13
Run-length encoding of a list (direct solution).
Implement the so-called run-length encoding data compression method directly. I.e. don’t explicitly create the sublists containing the duplicates, as in problem 9, but only count them. As in problem 11, simplify the result list by replacing the singleton terms (1 X) by X.
[1 1 1 2 2 3 1 5 5 3 3] -> [(3 1) (2 2) 3 1 (2 5) (2 3)]
Problem 14
Duplicate the elements of a list.
[1 2 3 1] -> [1 1 2 2 3 3 1 1]
Problem 15
Replicate the elements of a list a given number of times.
[1 2 3 1] 3 -> [1 1 1 2 2 2 3 3 3 1 1 1]
Problem 16
Drop every N`th element from a list.
[1 2 3 4 5 6 7 8] 3 -> [1 2 4 5 7 8]
Problem 17
Split a list into two parts; the length of the first part is given.
Do not use any predefined predicates.
[1 2 3 4 5 6 7 8] 3 -> ([1 2 3] [4 5 6 7 8])
Problem 18
Extract a slice from a list.
Given two indices, I and K, the slice is the list containing the elements between the I`th and K`th element of the original list (both limits included). Start counting the elements with 1.
Problem 19
Rotate a list N places to the left.
[1 2 3 4 5 6 7 8] 3 -> [4 5 6 7 8 1 2 3]
Problem 20
Remove the K`th element from a list.
[1 2 3 4] 2 -> (2, [1 3 4])
Problem 21
Insert an element at a given position into a list.
[1 2 3 4] 2 5 -> [1 5 2 3 4]
Problem 22
Create a list containing all integers within a given range.
(4 9) -> [4 5 6 7 8 9]
Problem 23
Extract a given number of randomly selected elements from a list.
[1 2 3 4 5 6 7 8] 3 -> [7 3 5]
Problem 24
Lotto: Draw N different random numbers from the set 1..M.
(1 8) 3 -> [7 3 5]
Problem 25
Generate a random permutation of the elements of a list.
[1 2 3 4 5] -> [2 5 1 3 4]
To be continued...