Created
March 13, 2025 02:07
-
-
Save jluisflo/1c2b1c8fe53a38e0a5fdc11885a9bfa1 to your computer and use it in GitHub Desktop.
Esta es una solución al problema de calculo de población de aliens planteado por https://gist.github.com/cococov/a868d8255d99a657a51494ffc5866de6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Aliens | |
{ | |
private static void Main() | |
{ | |
int[] aliens = [3, 4, 3, 1, 2]; | |
const int maxDays = 80; | |
for (var day = 0; day <= maxDays; day++) | |
{ | |
Console.WriteLine($"Dia: {day}: {string.Join(",", aliens)}"); | |
var countAlienNeedToBorn = 0; | |
for (var alien = 0; alien < aliens.Length; alien++) | |
{ | |
if (aliens[alien] == 0)//necesita dar a luz un nuevo | |
{ | |
aliens[alien] = 6; | |
countAlienNeedToBorn++; | |
} | |
else | |
aliens[alien] -= 1; | |
} | |
if (countAlienNeedToBorn > 0) | |
{ | |
if (day == maxDays) //si es el ultimo dia no necesito incrementar la poblacion | |
break; | |
for (var i = 0; i < countAlienNeedToBorn; i++) | |
aliens = aliens.Append(8).ToArray(); | |
} | |
} | |
Console.WriteLine($"En el dia {maxDays} hay {aliens.Length} aliens"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment