Skip to content

Instantly share code, notes, and snippets.

@vKxni
Created September 25, 2022 19:48
Show Gist options
  • Save vKxni/65c2ea4025c3114ecf4997ffdf672e05 to your computer and use it in GitHub Desktop.
Save vKxni/65c2ea4025c3114ecf4997ffdf672e05 to your computer and use it in GitHub Desktop.
defmodule BirdCount do
def today([]), do: nil
def today(list), do: hd(list)
def increment_day_count([]), do: [1]
def increment_day_count([h | t]), do: [h + 1 | t]
def has_day_without_birds?([]), do: false
def has_day_without_birds?([0 | _]), do: true
def has_day_without_birds?([_ | t ]), do: has_day_without_birds?(t)
def total([]), do: 0
def total([h | t]), do: h + total(t)
def busy_days([]), do: 0
def busy_days([h | t]) when h >= 5, do: 1 + busy_days(t)
def busy_days([_ | t]), do: busy_days(t)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment