Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By JosAH

Thread: The sweet program

  1. #1
    wdaniels is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default 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.

    I'm totally confused please help!!!!!!
    Any assistance will be appreciated

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default 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
    jammas615 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    wdaniels is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default 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. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default Re: The sweet program

    Quote Originally Posted by wdaniels View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    wdaniels is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default Re: The sweet program

    ok let me look that up

    thanks

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default Re: The sweet program

    Quote Originally Posted by wdaniels View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  4. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •