Skip to content

vkatsuba/enn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

74 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

enn - Erlang Ninety Nine Problems

enn is small project of Erlang Ninety Nine Problems. Here provided a simple solution of Erlang Ninety Nine Problems.

Contents

Goals

enn aims to provide a simple solutions of Erlang Ninety Nine Problems.

Build & Run

$ git clone https://github.com/vkatsuba/enn.git
$ cd enn
$ make

Documentation

The examples of 99 problems was get from Ninety-Nine Lisp Problems

Erlang 99 Problems

Problem 01

(C) Find the last box of a list. Example: p01.erl

1> p01:run([a, b, c, d]).
d

Problem 02

(C) Find the last but one box of a list. Example: p02.erl

1> p02:run([a, b, c, d]).
[c,d]

Problem 03

(C) Find the K'th element of a list. Example: p03.erl

1> p03:run([a, b, c, d, e], 3).
ั

Problem 04

(C) Find the number of elements of a list. Example: p04.erl

1> p04:run([a, b, c, d, e]).
5

Problem 05

(C) Reverse a list. Example: p05.erl

1> p05:run([a, b, c, d, e]).
[e,d,c,b,a]

Problem 06

(C) Find out whether a list is a palindrome. Example: p06.erl

1> p06:run([a, b, c, b, a]).
true

Problem 07

(C) Flatten a nested list structure. Example: p07.erl

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

Problem 08

(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]

Problem 09

(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]]

Problem 10

(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}]

Problem 11

(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}]

Problem 12

(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]

Problem 13

(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]

Problem 14

(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]

Problem 15

(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]

Problem 16

(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]

Problem 17

(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]]

Problem 18

(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]

Problem 19

(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]

Problem 20

(C) Remove the K'th element from a list. Example:

1> p20:run([a, b, c, d], 2).
[a,c,d]

To be continued ...

Support

v.katsuba.dev@gmail.com