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.
I'm totally confused please help!!!
what sort of structure would i use and how?
Well, you could keep a list of numbers -- one for each child -- and also have a variable which keeps track of the index of the last child removed. You remove element with index (i+m) mod size, and repeat until the size of the list is 1.
A bitset squeezes 64 true/false values into the space of a long integer (64 bits). It is a bit like a boolean with 64 elements. If you want to change the size of the array whenever a child picks a sweet, the List might be a better bet.
I wouldn't use numbers to represent children, or any kind of clever math calculations. I would use objects to represent the things in the problem. Thus a Child class that has an instance of a Sweet class that can be null. I like Fred's suggestion, though I personally find ArrayList easier to use so I would do that.