public class Game {
private int len;//1,2,3......n
private int stepLen;//m
private int steps = 1;
private int currentIndex = 0;
private int printed = 0;
private int[] a;
public Game(int n, int m) {
this.len = n;
this.stepLen = m;
a = new int[n];
fill(a);
}
private void fill(int[] a) {
for (int i = 0; i < a.length; i++) {
a[i] = i + 1;
}
}
public void print() {
while (printed < len) {
if (getSteps() == stepLen) {
doPrint();
}
keepMoving();
}
}
private void keepMoving() {
currentIndex += 1;
if (currentIndex >= len) currentIndex = 0;
if (a[currentIndex] != 0) {
steps += 1;
}
}
private void doPrint() {
System.out.println(a[currentIndex]);
printed += 1;
a[currentIndex] = 0;
steps = 0;
}
private int getSteps() {
return steps;
}
}