In a small town the population is `p0 = 1000` at the beginning of a year. The population
regularly increases by `2 percent` per year and moreover `50` new inhabitants per year
come to live in the town. 
How many years does the town need to see its population
greater or equal to `p = 1200` inhabitants?

```
At the end of the first year there will be: 
1000 + 1000 * 0.02 + 50 => 1070 inhabitants

At the end of the 2nd year there will be: 
1070 + 1070 * 0.02 + 50 => 1141 inhabitants (number of inhabitants is an integer)

At the end of the 3rd year there will be:
1141 + 1141 * 0.02 + 50 => 1213

It will need 3 entire years.
```
More generally given parameters:

`p0, percent, aug (inhabitants coming or leaving each year), p (population to surpass)`

the function `nb_year` should return `n` number of entire years needed to
get a population greater or equal to `p`.

aug is an integer, percent a positive or null number, p0 and p are positive integers (> 0)
```
Examples:
nb_year(1500, 5, 100, 5000) -> 15
nb_year(1500000, 2.5, 10000, 2000000) -> 10
```

Note: Don't forget to convert the percent parameter as a percentage in the body of your function: if the parameter percent is 2 you have to convert it to 0.02.

Difficulty: introductory

Starter code:

def nb_year(p0, percent, aug, p):
	

Solutions:
def nb_year(population, percent, aug, target):
    year = 0
    while population < target:
        population += population * percent / 100. + aug
        year += 1
    return year

def nb_year(p0, percent, aug, p, years = 0):
    if p0 < p:
        return nb_year(p0 + int(p0 * percent / 100) + aug, percent, aug, p, years + 1)
    return years

def nb_year(p0, percent, aug, p):
    return 0 if p0 >= p else nb_year(p0 + p0 * percent/100 + aug, percent, aug, p)+1


def nb_year(p0, percent, aug, p):
    # base case
    if p0 >= p:
        return 0

    # recursive case
    _p = percent / 100.00
    p0 = p0 + round(p0 * _p) + aug  # growth of population formula
    return 1 + nb_year(p0, percent, aug, p)


from math import ceil, log
def nb_year(p0, percent, aug, p):
    if not percent: return ceil(1.*(p - p0) / aug)
    percent = 1 + percent / 100.
    r = aug / (1 - percent)
    return ceil(log((p - r) / (p0 - r), percent))

def nb_year(p0, percent, aug, p):
    i = 0    
    while p0 < p:
        p0 = p0 + (p0 * percent * 0.01) + aug
        i += 1
    return i

def nb_year(p0, percent, aug, p):
    current_population = p0
    years = 0
    while current_population < p:
        new_population = current_population + current_population * percent / 100 + aug
        current_population = new_population
        years += 1
    return years
     


def nb_year(p0, percent, aug, p):
  y = 0
  while p0 < p: p0, y = p0 * (1 + percent / 100.0) + aug, y + 1
  return y

from math import floor

def nb_year(p0, percent, aug, p):
    i = 1
    mult = 1 + percent / 100.0
    prev = p0
    while (prev < p):
        ne = floor((prev * mult + aug))
        prev = ne
        i += 1
    return (i - 1)

def nb_year(p0, percent, aug, p):
    i = 0
    while p0 < p:
        p0 += p0*percent/100 + aug
        i += 1
    return i

def nb_year(p0, percent, aug, p):
    # your code
    sum = p0
    percent_value = percent / 100
    years = 0
    while (sum < p):
        years +=1
        sum += sum*percent_value + aug
    return years

# Growth of a Population
def nb_year(p0, percent, aug, p, n=0):  # Added n=0.
  while p0 < p:
    p0 += aug + (p0 * percent / 100)
    n += 1
  return n

def nb_year(p0, percent, aug, p):
    years = 0
    while p0 < p:
        p0 +=  ((p0/100)*percent) + aug
        years += 1
    return years

print(nb_year(1500000, 0.25, 1000, 2000000))

def nb_year(x,p,a,y):
    t = 0
    while True:
        x += x*p/100 + a
        t += 1
        if x >= y:
            break
    return t

def nb_year(p0, percent, ag, p):
    year = 0
    while p0 < p:
        year += 1
        p0 = p0 * (1+percent/100) + ag
    return year

def nb_year(p0, percent, aug, p):
    year=0
    while p0 < p:
        p0=p0+p0*(percent/100)+aug
        year=year+1
    return year
    
    
    # your code


def nb_year(y,e,a,r,s=0):
    while y<r:y+=y*e*.01+a;s+=1
    return s

nb_year=n=lambda a,b,c,d,e=0:n(
a+a*b*.01+c
,b,c,d,e+1)if a<d else e

nb_year=lambda p0,percent,aug,p,c=0: c if p<=p0 else nb_year(p0*(1+percent/100)+aug,percent,aug,p,c+1)

from itertools import accumulate

def nb_year(p0, pct, aug, p):
  return next(i for i, x in enumerate(accumulate([p0] * 1000, lambda px, _: px + .01 * pct * px + aug)) if x >= p)

def nb_year(p0, percent, aug, p):
    pop=p0
    y=0
    while pop<p:pop*=(1+percent/100);pop+=aug;y+=1
    return y


def nb_year(p0, percent, aug, p):
    n = p0 + p0* (percent/100) + aug
    nb= 1 
    while n < p:
        n = n + n*(percent/100) + aug
        nb += 1
    return(nb)