The basic idea of this is that in a planet there is three diferent kinds of species, only two of the three species can came together to procreate, and the result is that this to species die a two new sobjects of the third species born, for example we have a b and c, and the species a and b came together and let 2 c new members born.
It is like: 1a 1b and 1c (Sorry for the lenguage)
When a and b want to have kids they came together and die but have two kids, these new kids are from the species c, so the result is:
0a 0b and 3 c
In this casie we said that the planet succed and c is the dominating spcecies. But when I have 3a 4b 2c and I need to see if any of the three species could succed in the planet.
I thought that I could do it with a recursive solution, but I get always the error of:
Exception in thread "main" java.lang.StackOverflowError
In the function I am trying to use recursive.
This is my code, I know something is wrong but I don´t know what.
public class Automata2 {
public static void main(String[] args) {
int N = 2;
while (N <= 14) {
partition(N);
N++;
}
}
public static void partition(int N) {
int n1,n2,n3;
for(n1=0;n1<=N;n1++){
for(n2=0;n2<=N;n2++){
for(n3=0;n3<=N;n3++){
if((n1+n2+n3)==N){
strPlanetA(n1, n2, n3);
}
}
}
}
}
public static void strPlanetA(int a, int b, int c){
int a2 = a, b2 = b, c2 = c;
while (!(a2!=0 && b2==0 && c2==0)) {
a2=a2+2;
b2--;
c2--;
if (a2==a && b2==b && c2==c) {
System.out.println("Not Fail");
}
if (a2!=0 && b2==0 && c2==0) {
System.out.println("Fail in A");
}
strPlanetA(a2, b2, c2);
}
}
}
The partition is only to get all the population posible in the planet, I need to see if the plane succed in a planet with population from 2 until 14.