1. Member
Join Date
Oct 2011
Posts
3
Rep Power
0

## The sweet program

hi

i'm new!!!!

my problem:

n children numbered 1 to n are sitting in a circle. starting at child 1, a sweet is passed. after m passes the child holding the sweet is eliminated. if child x gets eliminated he gives the sweet to child x+1 and leaves the ring. that does not count far a pass. the children in the circle close ranks and the game continues with the child who was sitting after the eliminated child,taking the sweet. assume m is constant for each elimination.
write a program that will determine which child would get the sweet in the end.

Any assistance will be appreciated

2. ## Re: The sweet program

The original problem is the Josephus problem and it is about people being killed one by one; it was not so sweet ;-)

kind regards,

Jos

3. Member
Join Date
Oct 2011
Posts
3
Rep Power
0

## Re: The sweet program

ok!

that is some hectic maths. how would i formulate the code for the problem.

do you have an example
regards

4. ## Re: The sweet program

Originally Posted by wdaniels
ok!

that is some hectic maths. how would i formulate the code for the problem.

do you have an example
regards
Use a boolean array and consider it circular, i.e. hopping off from the end brings you back to the first element. If an element is true, the corresponding person is considered to be alive, else hop to the right again until you hit an element that is still true.

kind regards,

Jos

5. Member
Join Date
Oct 2011
Posts
3
Rep Power
0

## Re: The sweet program

ok let me look that up

thanks

6. ## Re: The sweet program

Originally Posted by wdaniels
ok let me look that up

thanks
You're welcome of course; another possibility is using a BitSet; it has a method that can find the next set bit for you; a BitSet can be interpreted as a boolean array.

kind regards,

Jos