Total GDP can grow while each person's share shrinks, if the population grows faster. A valley's statistics office has real GDP for years 0, 1, ..., n (gdp, in millions of crowns) and the population in year 0 (pop0, in thousands). It does not count people every year; instead it estimates that the population grew by the rate pop_growth[t-1] from year t-1 to year t (a fraction; 0.02 means 2 %, and a negative rate means it shrank):
N_0 = \texttt{pop0} \qquad N_t = N_{t-1}\,(1 + \texttt{pop\_growth}[t-1])
GDP per capita in year t is \texttt{gdp}[t] / N_t (thousands of crowns per person), and its growth rate in year t \ge 1 is \dfrac{\text{per capita}_t}{\text{per capita}_{t-1}} - 1.
Write per_person(gdp, pop0, pop_growth) that returns a tuple (per_capita, growth, poorer):
per_capita: GDP per capita for every year;growth: its growth rate for years1, ..., n;poorer: the yearst >= 1, in increasing order, in which total GDP rose (gdp[t] > gdp[t-1]) but GDP per capita fell.
Examples
Input: gdp = [1000, 1030, 1050, 1040, 1100], pop0 = 50,
pop_growth = [0.02, 0.025, 0.0, 0.01]
Output: ([20.0, 20.19607843137255, 20.086083213773314, 19.89478718316595, 20.834221155257563],
[0.009803921568627416, -0.005446365143263021, -0.00952380952380949, 0.04722010662604714],
[2])
Explanation: the population is 50, 51, 52.275, 52.275 and 52.79775 thousand. In year 2
GDP grew by about 1.9 % but the population by 2.5 %, so each person's share fell.
In year 3 per capita GDP fell too, but so did total GDP, so year 3 is not listed.
Input: gdp = [600, 600], pop0 = 3, pop_growth = [-0.25]
Output: ([200.0, 266.6666666666667], [0.3333333333333335], [])
Constraints
- per-capita GDP never stays exactly the same from one year to the next
- floats are compared with a tolerance of
1e-6
Goals
- Build a population series by compounding yearly growth rates
- Compute GDP per person and its yearly growth rate
- Find the years in which the economy grew but the average person got poorer