# The sweet program

• 10-07-2011, 08:14 AM
wdaniels
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:(sweat)::(sweat):
• 10-07-2011, 08:22 AM
JosAH
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
• 10-07-2011, 08:48 AM
wdaniels
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
• 10-07-2011, 09:03 AM
JosAH
Re: The sweet program
Quote:

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
• 10-07-2011, 09:21 AM
wdaniels
Re: The sweet program
ok let me look that up

thanks
• 10-07-2011, 10:08 AM
JosAH
Re: The sweet program
Quote:

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