MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / find_winner

Function find_winner

maths/josephus_problem.py:80–97  ·  view source on GitHub ↗

Find the winner of the Josephus problem for num_people and a step_size. Args: num_people (int): Number of people. step_size (int): Step size for elimination. Returns: int: The position of the last person remaining (1-based index). Examples: >>> fin

(num_people: int, step_size: int)

Source from the content-addressed store, hash-verified

78
79
80def find_winner(num_people: int, step_size: int) -> int:
81 """
82 Find the winner of the Josephus problem for num_people and a step_size.
83
84 Args:
85 num_people (int): Number of people.
86 step_size (int): Step size for elimination.
87
88 Returns:
89 int: The position of the last person remaining (1-based index).
90
91 Examples:
92 >>> find_winner(7, 3)
93 4
94 >>> find_winner(10, 2)
95 5
96 """
97 return josephus_recursive(num_people, step_size) + 1
98
99
100def josephus_iterative(num_people: int, step_size: int) -> int:

Callers

nothing calls this directly

Calls 1

josephus_recursiveFunction · 0.85

Tested by

no test coverage detected