1. ## Josephus problem

Has anybody over here ever tried the Josephus problem?

In Massada, in ancient Greece, it was decided that there were too many prisoners and many should be executed. One prisoner was given a sword and all 1000 prisoners were instructed to stand in a circle. The one with the sword was instructed to kill the man on his left and then pass the sword to the next man on the left, who would then do the same. The circle would continue to get smaller as this continued, and the last man left would be set free. Josephus, one of the prisoners, placed himself at the correct position in the line-up to be the one remaining man at the end of this elimination. At what position did he place himself on the circle? Also, if the last two will be set free, where should Josephus direct his friend to stand?

I got the answer 977. Is it correct??

Post your codes too [if you want]

2. I got it correct (at least, I did if you did) on the second compilation attempt, and the first valid compilation.

Code:
```#include <list>
#include <iostream>

int main() {
std::list<int> people_nums;
int peopleCount=1000, finalNumberLiving=2;

for (int i = 0; i < peopleCount; ++i) {
people_nums.push_back(i);
}

typedef std::list<int>::iterator it;
it curPersonIt = people_nums.begin();

while (peopleCount > finalNumberLiving) {
it end = people_nums.end();
/* went passed end of list, wrap around */
if (curPersonIt == end) curPersonIt = people_nums.begin();

/* at last valid person in list, kill dude in front and wrap around */
if (curPersonIt == --end) curPersonIt = people_nums.erase(people_nums.begin());
/* somewhere not near end of list, kill the next guy, and pass sword to the next next guy */
else curPersonIt = people_nums.erase(++curPersonIt);

peopleCount--;
}

std::cout << "And the survivors are (person starting with the sword labelled with 0, next is 1, etc)\t";

for (it curSurvivor = people_nums.begin(); curSurvivor != people_nums.end(); ++curSurvivor) {
std::cout << *curSurvivor << ' ';
}

return 0;
}```

3. Hey cool thanks for confirming it.