Extend the Stats module with the function count/2 which given a list and a number returns number of times the number occurs in the list.
count([],_) should return 0.
Hints: * What is the count of 1 in a list of the form [1|tail]? * What is the count of 1 in a list of the form [4|tail]? * Generalise this to use n as the number and _ for don’t care when n is not the first element in the list.
Here is some sample output of how it should work:
iex(1)> xs = xs = Stats.sample(fn() -> Die.roll() end, 10) [1, 2, 5, 1, 4, 2, 3, 3, 1, 4] iex(2)> Stats.count(xs, 1) 3 iex(3)> Stats.count(xs, 6) 0
Extra: create a eye_count/1 function that takes a number n as input, samples Die.roll/0 n times and then returns the count of 1, 2, …, 6 and the generated list in a tuple.
Stats.eye_count(10) {[{1, 4}, {2, 2}, {3, 0}, {4, 0}, {5, 2}, {6, 2}], [6, 6, 5, 2, 2, 5, 1, 1, 1, 1]}
So this means that one was thrown 4 times, two 2 times, no threes and so on.
The order of the eyes do not matter, but all six must be in the list, even if a number of eyes was not thrown in the sample.
Hints: * Use the count/2 function to help you. * It is probably easiest to create a helper function to do the recursion over the eyes from 1 to 6 (or from 6 to 1).