[7kyu][fundamentals] Growth of a Population
https://www.codewars.com/kata/563b662a59afc2b5120000c6 n 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 than or equal to p = 1200 inhabitants?main
parent
11c4e28710
commit
e9a72107ed
@ -0,0 +1,18 @@
|
||||
export const nbYear = (p0: number, percent: number, aug: number, p: number): number => {
|
||||
|
||||
let year = 0
|
||||
|
||||
while (p0 < p) {
|
||||
p0 += Math.floor(p0 * percent / 100) + aug
|
||||
year++
|
||||
}
|
||||
|
||||
return year
|
||||
}
|
||||
|
||||
console.log(
|
||||
nbYear(1500, 5, 100, 5000), 15
|
||||
)
|
||||
console.log(
|
||||
nbYear(1500000, 2.5, 10000, 2000000), 10
|
||||
)
|
||||
Loading…
Reference in New Issue