exercism/elixir/bird-count/lib/bird_count.ex

19 lines
597 B
Elixir
Raw Normal View History

2023-12-18 05:39:17 +00:00
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