kostyushkin/e-99

E-99: Ninety-Nine Erlang Problems
Erlang
Fetching latest commitâ€¦
Cannot retrieve the latest commit at this time.
 Failed to load latest commit information. src .gitignore README.md

E-99: Ninety-Nine Erlang Problems

based on L-99: Ninety-Nine Lisp Problems

Working with lists

P01 (*) Find the last box of a list.
Example:

``````1> p01:last([a,b,c,d,e,f]).
[f]
``````

P02 (*) Find the last but one box of a list.
Example:

``````1> p02:but_last([a,b,c,d,e,f]).
[e,f]
``````

P03 (*) Find the K'th element of a list.
The first element in the list is number 1.
Example:

``````1> p03:element_at([a,b,c,d,e,f], 4).
d
2> p03:element_at([a,b,c,d,e,f], 10).
undefined
``````

P04 (*) Find the number of elements of a list.
Example:

``````1> p04:len([]).
0
2> p04:len([a,b,c,d]).
4
``````

P05 (*) Reverse a list.
Example:

``````1> p05:reverse([1,2,3]).
[3,2,1]
``````

P06 (*) Find out whether a list is a palindrome.
A palindrome can be read forward or backward; e.g. (x a m a x).
Example:

``````1> p06:is_palindrome([1,2,3,2,1]).
true
``````

P07 (**) 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).
Example:

``````1> p07:flatten([a,[b,[c,d],e]]).
[a,b,c,d,e]
``````

P08 (**) 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.
Example:

``````1> p08:compress([a,a,a,a,b,c,c,a,a,d,e,e,e,e]).
[a,b,c,a,d,e]
``````

P09 (**) Pack consecutive duplicates of list elements into sublists.
If a list contains repeated elements they should be placed in separate sublists.
Example:

``````1> p09:pack([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]]
``````