Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question #2: You are to simulate the motion of a drunken sailor (i.e. a random walk problem). The sailor is standing at the middle of

image text in transcribed
Question #2: You are to simulate the motion of a drunken sailor (i.e. a random walk problem). The sailor is standing at the middle of a pier on the shore side. The sailor's ship is directly across from him. The pier size is L paces long and w paces wide (i.e. the sailor starls at coordinates & w, o anst the ship is L paces away) and the ship stretches across the entire width of th pier. Due to the sailor's inebriated condition a straight walking path cannot be maintained. Each second the sailor attempts to take a step. There is a 25% chance that the sailor will go left, a 20% chance the sailor will go right, a 10% chance the sailor will stand still, and a 45% chance the sailor will go forward. Assume the sailor does not go backwards. If the sailor's position exceeds the dimensions of the pier (zero to W) they fall into the sea. If they make it to the other side they are safe at their ship. Write a program that takes L and w as user inputs. The motion of the sailor is then simulated. If the sailor falls into the sea an appropriate message should be output. If the sailor makes it to the ship the ti them should be output. For either case a plot showing the salor's path should be made. it took Hint: Use evenly distributed random numbers to determine what direction the sailor goes As always, this program should be fully commented. It should be submitted to D2L as sailor.m SHIP

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

Database Publishing With Filemaker Pro On The Web

Authors: Maria Langer

1st Edition

0201696657, 978-0201696653

More Books

Students also viewed these Databases questions