int numberOfPeople =1000;//Number of people in a group (starts counting at 0)
int nthPersonKilled =7;//How many people to skip before the killing (if counting from 1); if counting from 0, this is the person that will be killed.
//end of user input
int person[]=newint[numberOfPeople];//create array of people
int loopNumber =0;//used to count how many alive people have been skipped
int personCounter =0;//used to determine position in the circle
int sumOfLoop =1;//If this is greater than 0, there is someone alive and the program will keep looping. If < 1, then it will conclude and print winner.
int lastKilled;//Used for theatrics. It is the last person who was killed
void keepInCheck(){//Makes the array a circle (loops at or out of bounds person to beginning)
if(personCounter >= numberOfPeople){
personCounter =(personCounter - numberOfPeople);
}
}
void setup(){
//Set all people to 1 (alive). 0 is dead
for(int i=0; i < numberOfPeople; i++){
person[i]=1;
}
//Theatrics
print(numberOfPeople);
print(" people begin\n");
//Main loop
while(sumOfLoop >0){//If there is still at least one person alive
if(loopNumber == nthPersonKilled){//If the appropriate number of living people have been skipped over
if(person[personCounter]==1){//If the person is alive
person[personCounter]=0;//This kills the person
//Theatrics
print("Person ");
print(personCounter);
print(" has been killed\n");
print(sumOfLoop -1);
print(" remain alive\n");
//Cleanup
loopNumber =0;//reset person skipped counter
lastKilled = personCounter;//Only used to print who has won. Can be taken out to improve performance.
keepInCheck();//If on last person, the circle will begin again
}else{//If the person who should be killed is dead, move on
personCounter++;//Advances
keepInCheck();//Wraps if applicable
}
}elseif(person[personCounter]==1){//If the person is not the one to kill, check if they are alive
personCounter++;//advance loop
loopNumber++;//Count them as skipped over
keepInCheck();//Wrap if necessary
}else{//If the person is not the one to kill and is also dead
personCounter++;//keep counting
keepInCheck();//Wrap if necessary
}
//Count the number of people remaining
sumOfLoop =0;//Zero the sum
for(int i=0; i < numberOfPeople; i++){//add all values of the array
Main.java:2: error: class, interface, or enum expected
int numberOfPeople = 1000; //Number of people in a group (starts counting at 0)
^
Main.java:3: error: class, interface, or enum expected
int nthPersonKilled = 7; //How many people to skip before the killing (if counting from 1); if counting from 0, this is the person that will be killed.
^
Main.java:6: error: class, interface, or enum expected
int person[] = new int[numberOfPeople]; //create array of people
^
Main.java:7: error: class, interface, or enum expected
int loopNumber = 0; //used to count how many alive people have been skipped
^
Main.java:8: error: class, interface, or enum expected
int personCounter = 0; //used to determine position in the circle
^
Main.java:9: error: class, interface, or enum expected
int sumOfLoop = 1; //If this is greater than 0, there is someone alive and the program will keep looping. If < 1, then it will conclude and print winner.
^
Main.java:10: error: class, interface, or enum expected
int lastKilled; //Used for theatrics. It is the last person who was killed
^
Main.java:12: error: class, interface, or enum expected
void keepInCheck() { //Makes the array a circle (loops at or out of bounds person to beginning)
^
Main.java:15: error: class, interface, or enum expected
}
^
Main.java:20: error: class, interface, or enum expected
for (int i=0; i < numberOfPeople; i++) {
^
Main.java:20: error: class, interface, or enum expected
for (int i=0; i < numberOfPeople; i++) {
^
Main.java:22: error: class, interface, or enum expected
}
^
Main.java:26: error: class, interface, or enum expected
print(" people begin\n");
^
Main.java:29: error: class, interface, or enum expected
while (sumOfLoop > 0) { //If there is still at least one person alive
^
Main.java:34: error: class, interface, or enum expected
print("Person ");
^
Main.java:35: error: class, interface, or enum expected
print(personCounter);
^
Main.java:36: error: class, interface, or enum expected
print(" has been killed\n");
^
Main.java:37: error: class, interface, or enum expected
print(sumOfLoop - 1);
^
Main.java:38: error: class, interface, or enum expected
print(" remain alive\n");
^
Main.java:40: error: class, interface, or enum expected
loopNumber = 0; //reset person skipped counter
^
Main.java:41: error: class, interface, or enum expected
lastKilled = personCounter; //Only used to print who has won. Can be taken out to improve performance.
^
Main.java:42: error: class, interface, or enum expected
keepInCheck(); //If on last person, the circle will begin again
^
Main.java:43: error: class, interface, or enum expected
} else { //If the person who should be killed is dead, move on
^
Main.java:45: error: class, interface, or enum expected
keepInCheck(); //Wraps if applicable
^
Main.java:46: error: class, interface, or enum expected
}
^
Main.java:49: error: class, interface, or enum expected
loopNumber++; //Count them as skipped over
^
Main.java:50: error: class, interface, or enum expected
keepInCheck(); //Wrap if necessary
^
Main.java:51: error: class, interface, or enum expected
} else { //If the person is not the one to kill and is also dead
^
Main.java:53: error: class, interface, or enum expected
keepInCheck(); //Wrap if necessary
^
Main.java:54: error: class, interface, or enum expected
}
^
Main.java:57: error: class, interface, or enum expected
for (int i=0; i < numberOfPeople; i++) { //add all values of the array
^
Main.java:57: error: class, interface, or enum expected
for (int i=0; i < numberOfPeople; i++) { //add all values of the array
^
Main.java:57: error: class, interface, or enum expected
for (int i=0; i < numberOfPeople; i++) { //add all values of the array
^
Main.java:59: error: class, interface, or enum expected
}
^
Main.java:63: error: class, interface, or enum expected
print(lastKilled);
^
Main.java:64: error: class, interface, or enum expected
print(" was last alive\n");
^
Main.java:65: error: class, interface, or enum expected
print("Program Finished");
^
Main.java:66: error: class, interface, or enum expected
exit();
^
Main.java:67: error: class, interface, or enum expected
}
^
39 errors