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;
}