14,027,303 members
See more:
for a given number 'n' we put numbers form 1 to n around a table and start deleting the numbers starting from 2 like this:
============EXAMPLE===========
n=6
1 2 3 4 5 6 --> we delete 2,4,6
now we have: 1 _ 3 _ 5 _
then if we imagine them around a table after 6 we gotta delete 2 but since it has been deleted we delete the number after 2 which is 3. since they're around a table after 3 we gotta delete 1 (the number after 5). at the end we get to the number 5 which is the answer

What I have tried:

i cant translate this process into code especially the part that at the end of the array we gotta start from the beginning of the array especially the recursive function
Posted
Updated 15-Nov-18 5:19am
CPallini 15-Nov-18 7:48am

It looks a variant of the Josephus problem, see
https://en.wikipedia.org/wiki/Josephus_problem
Unless it is explicitley required, I wouldn't use recursion (at least it doesn't seee to me recursion is a natural approach in such a problem).
Patrice T 15-Nov-18 11:26am

Show what you have done.

## Solution 1

We do not do your homework for you. Exercises like homework are set to cement the knowledge from the course into your brain, to help you practice the new skills and to let your tutor know where you need extra help.

Give it a go. It is not as hard as you think. Then, if you are still stuck, come back and post your code, explain your problem and we will try to help
Aydin Homay 15-Nov-18 7:43am

AGREE

## Solution 2

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Get some paper and a pencil, and draw yourself a picture of the table. Add the numbers around it. Now "play the game" and follow the rules. When you get it right, do it again, but this time, draw the table as a string line, and go from the end of the table back to the start. When that works, do it again, but this time write down the rules you are following: what you did when and why. When you have then written down, do it again, but this time, follow just the rules you just wrote down. Does it work? When it does, those rules are basically your code, all you have to do is translate to to actual code. Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!

## Solution 3

You need to visit some Learn C tutorial to learn the basics. You must learn about arrays, malloc and free.

You must implement some recursive function which does the job. It could be with the prototype
`int* shortenArray(const int *array, int cnt);`

Top Experts
Last 24hrsThis month
 OriginalGriff 163 Dave Kreskowiak 85 Gerry Schmitz 65 Bryian Tan 50 #realJSOP 38
 OriginalGriff 2,531 Dave Kreskowiak 940 Patrice T 884 Maciej Los 846 Richard Deeming 773