Question: Please help me to write this exercise in python. After a lively night at sea, a sailor has awakened on a raft and has decided

Please help me to write this exercise in python.

Please help me to write this exercise in python. After a lively

night at sea, a sailor has awakened on a raft and has

decided go for a short stroll. He is a bit disoriented at

the moment, and will take step completely randomly. Unfortunately, if he falls

After a lively night at sea, a sailor has awakened on a raft and has decided go for a short stroll. He is a bit disoriented at the moment, and will take step completely randomly. Unfortunately, if he falls into the ocean in his current state then he will drown. But fortunately he will manage to take only a few steps before he falls asleep again. What is the probability that the sailor will survive his walk? The raft has dimensions NN. The sailor will take K steps. The sailor always takes a step in one of 4 directions (up, down, left, right), completely at random. The first input line contains the numbers N and K, separated by a single space. The second line contains the sailor's starting position X and Y, where the upper-left corner of the raft has coordinates (1,1), and the lower-right corner has coordinates ( N,N). On the output, write the probability that the sailor will survive, rounded to 3 digits after the decimal point. Sample input: Sample input \#2: Output: Sample input \#3: Output: Sample input \#4: ample input \#4: Output: Hint: For each time step, compute an NN matrix M where M(i,j) represents the probability that the sailor is currently at position (i,j). You can compute M(i,j) for any time step if you know M(i1,j),M(i+1,j),M(i,j1) and M(i,j+1) at the previous step. Specifically, it is the average of those four values. For example, consider the first sample input above, where the raft is 33. At time t=0, the probability matrix looks like this: 100000000 At t=1 : 01/401/400000=00.2500.2500000 For example, consider the first sample input above, where the raft is 33. At time t=0, the probability matrix looks like this: 100000000 At t=1: 01/401/400000=00.2500.2500000 At t=2 : 2/1601/1602/1601/1600=0.12500.06300.12500.06300 At t=3 : 05/6405/6403/6403/640=00.07800.07800.04700.0470 The sum of the probabilities at t=3 is 16/64=0.250, which is the probability that the sailor has survived his first three steps

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!