#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Exclamation Assassin game problem


    Hi!!
    Would anybody know how to solve this question?:

    The game of Assassin is a simple game played on university campuses where each player is assigned a target to assassinate by simply saying “you’re dead” to them. Of course with thousands of people on campus and only a few dozen in the game you never know who is looking to assassinate you. Once you assassinate someone you take on the target they were looking for. If this happens to be you then you are the winner. To ensure that this works properly the targets must form a continuous “chain.” Write a program that allows the user to enter their target assignments and output whether it is valid or not based on if there is a continuous “chain.” Each person in the list is represented by position in the list. The value at the position is their target.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,931
    Rep Power
    481
    chase the indexes until you get to the start. If the length of this cycle is the length of the list the game is valid.

    L = [1,2,0]
    Start your count at 0.
    Start at index 0. Save index 0.
    Add 1 to your count.
    Look up L[0]. It is 1.
    Is it 0?
    No.
    Add 1 to your count.
    Look up L[1]. It is 2.
    Is it 0?
    No.
    Add 1 to your count.
    Look up L[2]. It is 0.
    Is it 0?
    Yes.
    Is the count equal to the list length?
    Yes.
    These are valid assignments for the game.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo