Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python please 1) 100 dogs stand in a line. The first one holds a bag full of biscuits. Initially, none of the dogs has

In Python please

image text in transcribed

1) 100 dogs stand in a line. The first one holds a bag full of biscuits. Initially, none of the dogs has a stick. 2) Each dog along the line takes a turn as "runner" and carries the bag of biscuits. The runner starts with themselves and walks down the line of dogs giving or taking away biscuits. After they are done, the runners return to their position, handing the bag off to the next runner, and are done for the game. 3) The runner goes down the line of dogs, starting with themselves. For each dog whose position is a multiple of their own, then * if the dog has a stick, the runner takes it away. * if the dog has no stick, the runner gives a stick. (i.e., if runner is in position 7, they check whether they and dog 17 21 28 etc. have biscuits) Who has a stick at the end of the game? Hint: Start by importing some essentials from NumPy from numpy import zeros Create an array containing the number of biscuits each dog holds. biscuits = zeros (100) The values in biscuits can only be either 0 or 1 according to the rules. Be careful with array indexing: dog #1 is indicated by biscuits[0] You have two options for modeling the runner: a) Use the % operator to find modulus (remainder on division) to check if each dog is a multiple b) Use a step size in the range function to skip over dogs as the runner goes down the line Here's how to structure option b: At any one time, there are two players interacting, the runner with the bag, and the dog in the line where the runner stops. So, we need nested loops. The outer loop has each player taking a turn as runner. The inner loop goes thru each dog the runner interacts with. Note that the step size is runner+1 to account for the offset for runner in range(100): for dog in range(runner, 100, runner+1)

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

What is digital literacy? Why is it necessary?

Answered: 1 week ago

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago