Skip to content

Instantly share code, notes, and snippets.

@hunterliu1003
Created March 5, 2020 17:44
Show Gist options
  • Save hunterliu1003/51b014c6a5591a0f8a84661fa191b5fb to your computer and use it in GitHub Desktop.
Save hunterliu1003/51b014c6a5591a0f8a84661fa191b5fb to your computer and use it in GitHub Desktop.
coronavirus
const infected = days => {
const INCUBATION_PERIOD_DAYS = 2
const INFECT_PEOPLE = 2
let infectedTotal = 1
const computed = (days, defaultInfectedPeop) =>
Array(days + 1)
.fill()
.reduce((total, cur, day) => {
if (day < INCUBATION_PERIOD_DAYS) {
return total
} else {
return (
total +
defaultInfectedPeop * INFECT_PEOPLE +
computed(days - day, defaultInfectedPeop * INFECT_PEOPLE)
)
}
}, defaultInfectedPeop) - defaultInfectedPeop
return computed(days, infectedTotal) + infectedTotal
}
Array(21)
.fill()
.forEach((i, index) => {
console.log(`index ${index}: ${infected(index)}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment