enn is small project of Erlang Ninety Nine Problems. Here provided a simple solution of Erlang Ninety Nine Problems.
enn aims to provide a simple solutions of Erlang Ninety Nine Problems.
$ git clone https://github.com/vkatsuba/enn.git
$ cd enn
$ make
The examples of 99 problems was get from Ninety-Nine Lisp Problems
(C) Find the last box of a list. Example: p01.erl
1> p01:run([a, b, c, d]).
d
(C) Find the last but one box of a list. Example: p02.erl
1> p02:run([a, b, c, d]).
[c,d]
(C) Find the K'th element of a list. Example: p03.erl
1> p03:run([a, b, c, d, e], 3).
ั
(C) Find the number of elements of a list. Example: p04.erl
1> p04:run([a, b, c, d, e]).
5
(C) Reverse a list. Example: p05.erl
1> p05:run([a, b, c, d, e]).
[e,d,c,b,a]
(C) Find out whether a list is a palindrome. Example: p06.erl
1> p06:run([a, b, c, b, a]).
true
(C) Flatten a nested list structure. Example: p07.erl
1> p07:run([[[a]], b, c, [d, [[e]]]]).
[a,b,c,d,e]
(C) Eliminate consecutive duplicates of list elements. Example: p08.erl
1> p08:run([a, a, a, b, b, b, b, c, d, d, d, d, e, e, e]).
[a,b,c,d,e]
(C) Pack consecutive duplicates of list elements into sublists. If a list contains repeated elements they should be placed in separate sublists. Example: p09.erl
1> p09:run([a, a, a, a, b, c, c, a, a, d, e, e, e, e]).
[[a,a,a,a],[b],[c,c],[a,a],[d],[e,e,e,e]]
(C) Run-length encoding of a list. Use the result of problem P09 to implement the so-called run-length encoding data compression method. Consecutive duplicates of elements are encoded as lists (N E) where N is the number of duplicates of the element E. Example: p10.erl
1> p10:run([a, a, a, a, b, c, c, a, a, d, e, e, e, e]).
[{4,a},{1,b},{2,c},{2,a},{1,d},{4,e}]
(C) Modified run-length encoding. Modify the result of problem P10 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) lists. Example: p11.erl
1> p11:run([a, a, a, a, b, c, c, a, a, d, e, e, e, e]).
[{4,a},b,{2,c},{2,a},d,{4,e}]
(C) Given a run-length code list generated as specified in problem P11. Construct its uncompressed version. Example: p12.erl
1> p12:run([{4, a}, b, {2, c}, {2, a}, d, {4, e}]).
[a,a,a,a,b,c,c,a,a,d,e,e,e,e]
(C) 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 P09, but only count them. As in problem P11, simplify the result list by replacing the singleton lists (1 X) by X. Example: p13.erl
1> p13:run([{4, a}, {1, b}, {2, c}, {2, a}, {1, d}, {4, e}]).
[a,a,a,a,b,c,c,a,a,d,e,e,e,e]
(C) Duplicate the elements of a list. Example: p14.erl
1> p14:run([a, b, c, d, e]).
[a,a,b,b,c,c,d,d,e,e]
(C) Replicate the elements of a list a given number of times. Example: p15.erl
1> p15:run([a, b, c, d, e], 3).
[a,a,a,b,b,b,c,c,c,d,d,d,e,e,e]
(C) Drop every N'th element from a list. Example: p16.erl
1> p16:run([a, b, c, d, e, f, g, h, i, k], 3).
[a,b,d,e,g,h,k]
(C) Split a list into two parts; the length of the first part is given. Example: p17.erl
1> p17:run([a, b, c, d, e, f, g, h, i, k], 3).
[[a,b,c],[d,e,f,g,h,i,k]]
(C) 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. Example: p18.erl
1> p18:run([a, b, c, d, e, f, g, h, i, k], 3, 7).
[c,d,e,f,g]
(C) Rotate a list N places to the left. Hint: Use the predefined functions length and append, as well as the result of problem P17. Example: p19.erl
1> p19:run([a, b, c, d, e, f, g, h], 3).
[d,e,f,g,h,a,b,c]
2> p19:run([a, b, c, d, e, f, g, h], -2).
[g,h,a,b,c,d,e,f]
(C) Remove the K'th element from a list. Example:
1> p20:run([a, b, c, d], 2).
[a,c,d]