DHEERAJHARODE / Hacktoberfest2023-Open-source-

Send your valuable codes here
MIT License
394 stars 3.16k forks source link

Josephus Problem Recursive Solution #909

Open Coderayush13 opened 1 year ago

Coderayush13 commented 1 year ago

In Josephus problem, n people are standing in a circle waiting to be executed and in every iteration, we kill the kth person and remove that person from the circle.

This procedure is repeated with the remaining people, starting with the (k+1)th person going in the same direction and killing the kth person, until only one person remains and is not killed.

We have to find the survivor position in the initial circle–given n the number of people standing in the circle initially and k the kth person to be executed.

JosephusProblem(n, k)– represents this problem.

JosephusProblem(8, 2)– 8 people are standing in a circle and in every iteration we kill the 2nd person.

First of all, the person at position 2 is killed, then the person at position 4 is killed, then the person at position 6 is killed then the person at position 8 is killed. , Then the persons at positions 3, 5, 7 are killed. So the person at position 1 survives.

t35ting commented 1 year ago

Assign this to me Please.

SanjoySaha24 commented 1 year ago

Please assign this to me.

Sandyy07 commented 1 year ago

Hi @1dharode , Kindly please assign me this issue.

amankayat commented 1 year ago

In this problem,There are N people standing in a circle waiting to be executed. The counting out 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 elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom.

Given the total number of persons N and a number k which indicates that k-1 persons are skipped and the kth person is killed in a circle. The task is to choose the person in the initial circle that survives.

Example: Input: N = 7 and k = 3 Output: 4 Explanations: The persons at positions 3, 6, 2, 7, 5, and 1 are killed in order, and the person at position 4 survives. download

nisthajnn commented 1 year ago

please assign this to me @Coderayush13

Puneet-03 commented 1 year ago

please assign this issue to me @Coderayush13 . I have also seen about this problem on numberphile and can provide a good solution for the same

Anupamk06 commented 1 year ago

@Coderayush13 please assign this task to me

amanverma2253 commented 1 year ago

Can you please assign this issue to me ?