Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need to solve this problem. reuirement is following. i have this so far, i need help to make it meets its requirements asked. def

i need to solve this problem. reuirement is following. image text in transcribedi have this so far, i need help to make it meets its requirements asked.

def getJosephusPosition(n, m): class Node: def __init__(self, data=None, next=None): self.set_data(data) self.set_next(next) def set_data(self, data): self.data=data def get_data(self): return self.data def set_next(self, next): self.next=next def get_next(self): return self.next def has_next(self): return self.next != None answer=[] head = Node(0) prev=head for n in range(1,n): currentNode=Node(n) prev.set_next(currentNode) prev = currentNode prev.set_next(head) CurrentNode=head counter=0 while currentNode.get_next() != currentNode: counter=counter+1 if counter==m: counter=0 prev.set_next(currentNode.next) answer.append(currentNode.get_data()) else: prev=currentNode currentNode=currentNode.get_next() answer.append(currentNode.get_data()) return answer print(str(getJosephusPosition(5,2)))

Description: The Josephus problem (or Josephus permutation) is a theoretical mathematical problem defined by the following game: N people are sitting in a circle numbered 1 to N, clockwise. Starting at person number x, a token is passed in direction D, where D is either clockwise or anticlockwise. After M passes, the person holding the token is eliminated, the circle closes ranks, and the game continues with the person who was sitting after the eliminated person picking up the token. The last remaining person wins Task: Using a circular linked list, write a simulation to solve the Josephus problem as efficiently as possible Input: The input to the program consists of the following 4 command-line arguments N, a positive number indicating the number of people M, a nonnegative number indicating the number of passes x, the starting point D, a case-insensitive letter indicating token passing direction ('C' or 'U' for clockwise or anticlockwise, respectively) Output: A list of numbers written to standard output indicating the order of elimination, one number per line, and a message indicating the winner. Deliverables: A listing of the source code that includes the circular linked list and simulation code. Sample Input/Output: The following is correct input/output sample: $ python josephus.py 5 1 1 c N: 5, M: 1, x: 1, D: c 4 3 Won Important: .The simulation must work for general values of N, M, x, and D . The use of ANY container class other than the circular linked list is not permissible. The restriction includes Python's built-in types such as tuple, List, and dict. However, the class str is excluded In addition to manual code inspections, the code will be tested using automated tools. Programs that fail to adhere to the input/output specifications will not be graded Description: The Josephus problem (or Josephus permutation) is a theoretical mathematical problem defined by the following game: N people are sitting in a circle numbered 1 to N, clockwise. Starting at person number x, a token is passed in direction D, where D is either clockwise or anticlockwise. After M passes, the person holding the token is eliminated, the circle closes ranks, and the game continues with the person who was sitting after the eliminated person picking up the token. The last remaining person wins Task: Using a circular linked list, write a simulation to solve the Josephus problem as efficiently as possible Input: The input to the program consists of the following 4 command-line arguments N, a positive number indicating the number of people M, a nonnegative number indicating the number of passes x, the starting point D, a case-insensitive letter indicating token passing direction ('C' or 'U' for clockwise or anticlockwise, respectively) Output: A list of numbers written to standard output indicating the order of elimination, one number per line, and a message indicating the winner. Deliverables: A listing of the source code that includes the circular linked list and simulation code. Sample Input/Output: The following is correct input/output sample: $ python josephus.py 5 1 1 c N: 5, M: 1, x: 1, D: c 4 3 Won Important: .The simulation must work for general values of N, M, x, and D . The use of ANY container class other than the circular linked list is not permissible. The restriction includes Python's built-in types such as tuple, List, and dict. However, the class str is excluded In addition to manual code inspections, the code will be tested using automated tools. Programs that fail to adhere to the input/output specifications will not be graded

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions