有17個人圍成一圈(編號0~16),從第0號的人開始從1報數,凡報到3的倍數的人離開圈子,
然后再數下去,直到最后只剩下一個人為止,問此人原來的位置是多少號?
int [] people = new int[17];
int lastPeople = 0;
public void getTheLastPeople(){
for(int i = 0; i < people.length; i++){
people[i] = i+1;
}
int count = 0;
int countLast = 0;
int j = 0;
while(true){
for(j = 0; j < people.length; j++){
if(people[j] != 0){
count++;
people[j] = count;
System.out.println("people[" + j + "] = " + people[j]);
if (people[j] % 3 == 0) {
people[j] = 0;
countLast++;
if(countLast == 17){
lastPeople = j;
return;
}
}
}
}
}
}
int lastPeople = 0;
public void getTheLastPeople(){
for(int i = 0; i < people.length; i++){
people[i] = i+1;
}
int count = 0;
int countLast = 0;
int j = 0;
while(true){
for(j = 0; j < people.length; j++){
if(people[j] != 0){
count++;
people[j] = count;
System.out.println("people[" + j + "] = " + people[j]);
if (people[j] % 3 == 0) {
people[j] = 0;
countLast++;
if(countLast == 17){
lastPeople = j;
return;
}
}
}
}
}
}