Skip to content

This program solves the Josephus Problem. There are N people in a circle to be executed. The counting begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The problem finds the person in the initial circle that survives

Notifications You must be signed in to change notification settings

thaisserpac/Josephus

Repository files navigation

The program receives its input from the command line, and must have either two or three command-line parameters:

  • First, the number of zealots (must be from from 1 to 50)

  • Second, the "elimination gap" (the number n mentioned above)

  • Third, and optionally, an integer seed value (>0) for the random generator

It then produces a random list of zealot names, which are taken from a list of fifty 3-character first names, and which always include the name of our good friend Josehpus.

The program then first displays the full list of zealots, including Joe, and next begins the elimination process. It shows the name of each successive victim, followed by the list of remaining zealots after that victim has been eliminated.

Once the list has been reduced to a single zealot, it is clear that this particular zealot's position is the one Joe should be occupying before the process begins. It may be that he should just stay put, but more likely he will have to convice someone to exchange places with him. The program will end by advising him accordingly.

About

This program solves the Josephus Problem. There are N people in a circle to be executed. The counting begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The problem finds the person in the initial circle that survives

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published