fork download
  1. //User input
  2. int numberOfPeople = 1000; //Number of people in a group (starts counting at 0)
  3. 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.
  4. //end of user input
  5.  
  6. int person[] = new int[numberOfPeople]; //create array of people
  7. int loopNumber = 0; //used to count how many alive people have been skipped
  8. int personCounter = 0; //used to determine position in the circle
  9. 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.
  10. int lastKilled; //Used for theatrics. It is the last person who was killed
  11.  
  12. void keepInCheck() { //Makes the array a circle (loops at or out of bounds person to beginning)
  13. if (personCounter >= numberOfPeople) {
  14. personCounter = (personCounter - numberOfPeople);
  15. }
  16. }
  17.  
  18. void setup() {
  19. //Set all people to 1 (alive). 0 is dead
  20. for (int i=0; i < numberOfPeople; i++) {
  21. person[i] = 1;
  22. }
  23.  
  24. //Theatrics
  25. print(numberOfPeople);
  26. print(" people begin\n");
  27.  
  28. //Main loop
  29. while (sumOfLoop > 0) { //If there is still at least one person alive
  30. if (loopNumber == nthPersonKilled) { //If the appropriate number of living people have been skipped over
  31. if (person[personCounter] == 1) { //If the person is alive
  32. person[personCounter] = 0; //This kills the person
  33. //Theatrics
  34. print("Person ");
  35. print(personCounter);
  36. print(" has been killed\n");
  37. print(sumOfLoop - 1);
  38. print(" remain alive\n");
  39. //Cleanup
  40. loopNumber = 0; //reset person skipped counter
  41. lastKilled = personCounter; //Only used to print who has won. Can be taken out to improve performance.
  42. keepInCheck(); //If on last person, the circle will begin again
  43. } else { //If the person who should be killed is dead, move on
  44. personCounter++; //Advances
  45. keepInCheck(); //Wraps if applicable
  46. }
  47. } else if (person[personCounter] == 1) { //If the person is not the one to kill, check if they are alive
  48. personCounter++; //advance loop
  49. loopNumber++; //Count them as skipped over
  50. keepInCheck(); //Wrap if necessary
  51. } else { //If the person is not the one to kill and is also dead
  52. personCounter++; //keep counting
  53. keepInCheck(); //Wrap if necessary
  54. }
  55. //Count the number of people remaining
  56. sumOfLoop = 0; //Zero the sum
  57. for (int i=0; i < numberOfPeople; i++) { //add all values of the array
  58. sumOfLoop += person[i];
  59. }
  60. }
  61. //Theatrics
  62. print("Person ");
  63. print(lastKilled);
  64. print(" was last alive\n");
  65. print("Program Finished");
  66. exit();
  67. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
stdout
Standard output is empty