Challenge #8

The Josephus problem can be seen in the following ‘hot potato’ game. N people, numbered 1 to N, sit in a circle. Person #1 holds a hot potato and passes it to person #2. After M passes the person holding the potato is removed (leaving N-1 people) – the potato is picked up by the next player and play continues a further M passes. If N=5 and M=3 (5 people, and 3 passes), the sequence of elimination is 4, 3, 5, 2 and then #1 winning.

Write a program which takes inputs for N & M, and returns the elimination sequence – use a linked list!

Josephus