The 99 Prolog Problems were formulated many years ago by a teacher working at the University of Applied Sciences in Biel-Bienne, Switzerland. They were meant to teach students how to think in a way that is compatible with logical programming, allowing them to improve their skills in the process.
While functional programming isn't logical programming and Erlang is not Prolog, it used to be based on it and the syntax has remained quite similar*. Therefore I have decided to solve the 99 problems using Erlang.
I am solving the remade problems as they are stated on this page. The solutions are grouped into categories, starting with lists and ending at graphs.
The solutions will be grouped into modules according to the categories mentioned in the previous section.
To test the functions you can compile and run them from the Erlang shell. An example of doing so:
$ erl
1> c(list_prb).
{ok,list_prb}
2> list_prb:reverse([1,2,3]).
[3,2,1]
Once I'm done with all the problems I will consider writing unit tests for all functions.
- List problems - done, available in the file
list_prb.erl
. - Arithmetic problems - done, available in the file
arith_prb.erl
. - Logic and Codes problems - done, available in the file
logic_prb.erl
. - Binary Tree problems - started, in
tree_prb.erl
.
I hope that these solutions will be of inspiration to someone who, like me, decides to learn Erlang.
* I must admit, however, that reading Prolog code I can mostly see what it is suggesting but I don't have a clue how it does what it does :)