Results 1 to 5 of 5
  1. #1
    Digital.Oct is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default [find out the lucky position to survive]-will you help me please !

    This problem is a game where n objects are arranged in a circle and every mth object is deleted until 1 object is left.

    The original problem is said to derive from a suicide pact among 41 rebels trapped by the Romans in the first century. The rebels decided to kill every third person until one is left and can escape in a boat that can take only one person. Josephus, the historian who lived to tell the story quickly figured out where he should position himself from the starting point in the circle so that he would survive.


    Suppose you were in that situation with the only difference that you have your palm PC to quickly find out the lucky position to survive. Your program should be able to handle the following situation:

    n people (n > 0 ) are initially arranged in a circle, facing inwards, and numbered from 1 to n. The numbering from 1 to n proceeds consecutively in a clockwise direction.

    Starting with person number 1, counting continues in a clockwise direction, until we get to person number k (k > 0), who is promptly killed.

    Counting then proceeds from the person to his immediate left, to kill the kth person, and so on, until only one person remains.

    For example, when n = 5 and k = 2, the order of execution is 2, 4, 1, and 5. The survivor is 3.
    Hint you have to implement the circular list for your program to be efficient."how that could be !"



    Input
    Input data is to be read from a file roulette.in. Each line in this file contains values for n and k (in that order). A line containing values of 0 for n and k will terminate input. Your program does know not the maximum number of people taking part in this tragic event.
    Output
    For each input line, output in a file roulette.out the position of the sole survivor.
    Sample Input
    1 1
    1 5
    8 3
    0 0

    Sample Output
    1
    1
    7


    - to be serious with you i did not understand this question very well !!


    what am thinking about it now is the algorithm how they got from the 2 rows
    1 , 1 , 7 ! .. the example which given has no thing to understand !

    i have to understand this method"by words not by coding" to go ahead .. .. do not misunderstand me , i do not want someone to
    solve my assignment .. i want some one to be just as a supervisor . :)

    what am planed to do for now :
    read file.
    arranged in some how way in the circular LL
    used method which return to me after removing the survivor person.
    i thought that maybe i can used recursion .. i dunno why it seem to me just like binary search

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I didn't read your whole question yet, but this is the josepheth(or something like that) problem. I had a post on these forums with a few people giving tips for a math approach; I was able to solve it with an array list. Give it your best shot and post your attempts.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Use a BitSet and pay special attention to the nextBitSet( ... ) method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Digital.Oct is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    will you give me brief example about this method ! please ?
    .. i read about it in The Java programming language for Ken Arnold and James Gosling , there is only
    information with out examples ..

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Digital.Oct View Post
    will you give me brief example about this method ! please ?
    .. i read about it in The Java programming language for Ken Arnold and James Gosling , there is only
    information with out examples ..
    Have you read the API documentation for the BitSet class? It discusses all the methods in that class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Find index position of every word in a String
    By pentace in forum New To Java
    Replies: 6
    Last Post: 06-28-2009, 09:26 PM
  2. get position in string from caret position
    By helloworld111 in forum AWT / Swing
    Replies: 5
    Last Post: 02-19-2009, 02:36 AM
  3. BorderFactory to set position?
    By aleplgr in forum AWT / Swing
    Replies: 2
    Last Post: 01-30-2008, 01:46 PM
  4. Help with position in java
    By fernando in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 08:54 PM
  5. Use the mouse position
    By susan in forum Java Applets
    Replies: 1
    Last Post: 07-29-2007, 12:10 AM

Posting Permissions

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