Here is my attempt at Josephu's Circle problem. Curious to see if anyone had a different approach.
Best Regards.
PK
Code:/*
* Titus Flavius Josephus was an important first-century historian.
* Having survived the siege and destruction of Jerusalem in 70 AD,
* he authored several works on Jewish history, including The Jewish War
* and Antiquities of the Jews. Not only have his writings given valuable
* insight into first century Judaism, they provide an extra-Biblical
* account of early Christianity. But aside from the books, and the writings,
* and all of his other invaluable contributions to history, Josephus also told
* the story of how he had escaped death by quickly standing in the "safe spot"
* of what is now called Josephus’ Circle.
* As the legend goes, Josephus and forty of his fellow soldiers retreated
* from the siege of Yodfat to a small cave in the hills.
* Surrounded by the Roman legion with no chance of escape, the soldiers saw
* no other choice but to commit suicide. Like the people of Masada,
* they would rather die than face capture.
* In order to decide who would die in which order,
* the soldiers stood in a circle and,
* starting with the top of the circle and continuing clockwise, counted to three.
* The third man got the ax and the counting resumed at one.
* The process continued until there was no one left.
* Josephus, who didn't quite agree with
* the whole "we should all kill ourselves" idea,
* figured out the perfect way to avoid death: be the last man standing.
*
* Your challenge: write the Josephus function.
* There should be two inputs (number of soldiers, soldiers to skip)
* and one output (index of the safe spot).
*
* Original Post:
* http://thedailywtf.com/Articles/Programming-Praxis-Josephus-Circle.aspx
*/
package JosephusCircle;
import java.util.Scanner;
public class JosephusCircle{
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
//Initialize variables
int solders, counting_index, numAlive;
int counter = 0;
boolean lastOneStanding = false;
//Input Values
System.out.print("Please Enter the Number of Soilders: ");
numAlive = solders = console.nextInt();
System.out.print("Please Enter How Many to skip: ");
counting_index = console.nextInt();
//Initialize array, solders alive are considered "True"
boolean unit[] = new boolean[solders];
for (int i = 0; i < unit.length; i++){
unit[i] = true;
}
//loop iterates while lastOneStanding = false
while(!lastOneStanding){
// iterate through the array
for( int i = 0 ; i < unit.length; i++){
//Check if solder at position i is alive
if (unit[i]){
counter++;
// counter == counting index kill that soldier
if (counter == counting_index){
counter = 1;
numAlive--;
unit[i] = false;
}
}
}
//if numAlive == 1 set lastOneStanding to true to exit loop
if (numAlive == 1){
lastOneStanding = true;
}
}
//Find location for last living solder
int i = 0;
for ( ; !unit[i]; i++ ){}
System.out.print("Best Location to Stand: " + (i + 1) + "\n");
}
}

