Help shepherd to count sheep in Elixir

Shepard (Mass Effect)

I have been thinking about learning a functional language for a long time. So recently I’ve started to play around with Elixir. I am reading official guide and docs for theory. And also I do simple katas on Codewars for practice.

The last kata is Counting sheep… And I’ve come up with 13 solutions for it. Let me show it to you and explain why I need so many.


Consider an array of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).

For example,

[true,  true,  true,  false,
true, true, true, true ,
true, false, true, false,
true, false, false, true ,
true, true, true, true ,
false, false, true, true]

The correct answer would be 17.

Solution boilerplate

Sample Tests

My solutions

When I first saw this kata I had very small grasp on how to solve it or cycle through a list in Elixir in general. So I had to look for some clues in guides.

Also during my little investigation I browsed docs on Enum and List and I was curious to try few functions from there too. Lastly, while I am still on that task I decided to try out syntax peculiarities of Elixir that I already read about.

So this ends my little story on learning a new language. I think this is an interesting approach: take a relatively simple task in a new language and try to solve it in different ways. I see quite a few benefits here.

It would be cool if you propose your solution in comments or share your thoughts on how to learn a new language.