Skip to content

Instantly share code, notes, and snippets.

@bran921007
Created April 4, 2015 21:21
Show Gist options
  • Save bran921007/f28486a122a4130c77a1 to your computer and use it in GitHub Desktop.
Save bran921007/f28486a122a4130c77a1 to your computer and use it in GitHub Desktop.
Funcion recursiva - Problema de la bacteria y termino An de la sucesion
Problema:
The XYZ bacteria is studied by a Harvard student
The bacterium is a hermaphrodite, it is able to reproduce itself by him without the intervention of a bacterium of the opposite sex.
It has been discovered that under temperate climatic conditions this bacterium is reproduced twice at full life creating two new microbes.
A constraint to consider is that, for reasons not yet discovered the first bacteria populations of microbes is replicated five times, creating 5 new microbes.
Create a recursive function (no multiplication or loops) to determine the total population given the initial number of these microbes.
determinatePopulation (0) -> 0
determinatePopulation (1) -> 6
determinatePopulation (2) -> 9
determinatePopulation (3) -> 12
determinatePopulation (4) -> 15
=======================================
Respuesta:
function determinatePopulation(n){
if(n == 0){
return 0;
}else if(n == 1){
return 6;
}else{
return 3 + determinatePopulation(n-1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment