Make a generic count/2 function
In the Stats module you should create a function count/2 that takes two arguments:
count(n, list)
It should return the number of times n appears in list.
Example:
iex(1) > list = [1,2,2,4,5,3,3,2] [1, 2, 2, 4, 5, 3, 3, 2] iex(2)> Stats.count(2, list) 3 iex(3)> Stats.count(3, list) 2 iex(4)> Stats.count(6, list) 0
Descriptive statistics for dice rolling
Create a function in Stats
d6stats(rolls)
that takes a list of rolls of a 6 sided die and returns a list of tuples. Each tuple should be of the form {eyes, count}.
Example:
iex(1) > list = [1,2,2,4,5,3,3,2] [1, 2, 2, 4, 5, 3, 3, 2] iex(2)> Stats.d6stats(list) [{1,1}, {2,3}, {3,2}, {4,1}, {5,1}, {6,0}]
Hint: use the Stats.count/2 function and a list comprehension to calculate resulting list.