Skip to content

Latest commit

 

History

History

josepheus_problem

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Josepheus Problem

the Josephus problem (or Josephus permutation) is a theoretical problem related to a certain counting-out game.

Description

People are standing in a circle waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed.

The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains, and is freed.

The Problem

Given the number of people and number to be skipped, the problem is to choose the position in the initial circle to avoid execution.

Note

This algorithm is considering the 0 as a initial position. Also implements the left-right direction. But don't worry, you can change it easily to attends to your needs!

Tests

You can discover and practice more about this problem on URI. Here some cool problems to solve:

  1. https://www.urionlinejudge.com.br/judge/pt/problems/view/1030
  2. https://www.urionlinejudge.com.br/judge/pt/problems/view/1031