bird-count
This commit is contained in:
18
elixir/bird-count/lib/bird_count.ex
Normal file
18
elixir/bird-count/lib/bird_count.ex
Normal file
@@ -0,0 +1,18 @@
|
||||
defmodule BirdCount do
|
||||
def today([]), do: nil
|
||||
def today([head | _tail]), do: head
|
||||
|
||||
def increment_day_count([]), do: [1]
|
||||
def increment_day_count([head | tail]), do: [head + 1 | tail]
|
||||
|
||||
def has_day_without_birds?([]), do: false
|
||||
def has_day_without_birds?([0 | _tail]), do: true
|
||||
def has_day_without_birds?([_head | tail]), do: has_day_without_birds?(tail)
|
||||
|
||||
def total([]), do: 0
|
||||
def total([head | tail]), do: head + total(tail)
|
||||
|
||||
def busy_days([]), do: 0
|
||||
def busy_days([head | tail]) when head >= 5, do: 1 + busy_days(tail)
|
||||
def busy_days([_head | tail]), do: busy_days(tail)
|
||||
end
|
||||
Reference in New Issue
Block a user