[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?
This commit is contained in:
2024-10-03 13:04:36 +03:00
parent 11c4e28710
commit e9a72107ed
+18
View File
@@ -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
)