Click here to Skip to main content
14,027,303 members
Rate this:
Please Sign up or sign in to vote.
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:
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
Updated 15-Nov-18 5:19am
CPallini 15-Nov-18 7:48am
It looks a variant of the Josephus problem, see
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.
Rate this: bad
Please Sign up or sign in to vote.

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
Rate this: bad
Please Sign up or sign in to vote.

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!
Rate this: bad
Please Sign up or sign in to vote.

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);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190419.4 | Last Updated 15 Nov 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100