-1

I have 3 integer as input: a, b and c. I'm trying to create a function to calculate the number progress at which a match will occur.

I used the following code to output the number and then the combination of input numbers. I'm trying to create a function where I can input a, b, and, c and it will return the progress for which x==a,y==bandz==c`.

int progress = 0;
for (int x = 0; x <= 160; x++) {
    for (int y = 0; y <= 160; y++) {
        for (int z = 0; z <= 160; z++) {
            progress++;
            System.out.println(progress + " " + x + " " + y + " " + z);
        }
    }
}
jhamon
  • 3,603
  • 4
  • 26
  • 37
bber
  • 3
  • 3

1 Answers1

0

Your formula is:

progress = 1 + z_iterations
progress = 1 + z + 161*y_iterations
progress = 1 + z + 161*( y + 161*x_iterations )
progress = 1 + z + 161*( y + 161*x )

Final form:

progress = 1 + z + 161*y + 25921*x  

You method should be:

public int computeProgress (int a, int b, int c) {
    return 1 + c + 161*b + 25921*a;
}
jhamon
  • 3,603
  • 4
  • 26
  • 37