DEV Community

Discussion on: Daily Challenge #120 - Growth of a Population

Collapse
 
bjorngrunde profile image
Björn Grunde

Elixir variant :)

@doc """
     iex> nb_year(1150, 2, 30, 5000)
     iex> 46
  """
  def nb_year(p0, percent, aug, p, year \\ 0) do
    if p0 >= p,
      do: year,
      else: nb_year(p0 + p0 * (percent / 100) + aug, percent, aug, p, year + 1)
  end