Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A board game has a track containing l squares, numbered from to . Initially, a target is placed randomly at initial position x 0 .

A board game has a track containing l squares, numbered from to . Initially, a target is placed randomly at initial position x0.

There are p players, and each chooses an initial step size from 1 to 10. Let si denote the chosen initial step size of player i.

On a player's turn, one of their actions is to advance the target by their current step size. After doing so, their step size is multiplied by a fixed value k, which was chosen at the start of the game.

Find the square the target will be in after n moves has been made.

Input Format

Line 1: l k p Line 2: s_1 s_2 ... s_p Line 3: x_0 n

Sample Input 0

10 2 3

3 1 4

5 4

Sample Output 0

9

Explanation 0

There are 10 squares on the track and the target starts at square 5. The 3 players have selected step sizes of 3, 1 and 4 respectively. We are asked to determine the location of the target after 4 moves have been played. The table below sets out the movement of the target and the step sizes as each turn is completed.

Move #

Comment

Target Posn

Step Sizes

0

Initial configuration

0 1 2 3 4 X 6 7 8 9

[3, 1, 4]

1

Player 1 moves 3 steps

0 1 2 3 4 5 6 7 X 9

[6, 1, 4]

2

Player 2 moves 1 step

0 1 2 3 4 5 6 7 8 X

[6, 2, 4]

3

Player 3 moves 4 steps

0 1 2 X 4 5 6 7 8 9

[6, 2, 8]

4

Player 1 moves 6 steps

0 1 2 3 4 5 6 7 8 X

[12, 2, 8]

At this point, all 4 moves have been completed, the target is at position 9, so we output 9

i

# Complete the 'find_pos' function below.

# The function is expected to return an INTEGER.

# The function accepts following parameters:

# 1. INTEGER l

# 2. INTEGER k

# 3. INTEGER_ARRAY steps

# 4. INTEGER x0

# 5. INTEGER n

#

def find_pos(l, k, steps, x0, n):

# Return the final position of the marker after n moves

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

More Books

Students also viewed these Databases questions