A drunken pirate is staggering up a gangplank from the dock to his ship. The gangplank is 5 paces wide and 15 paces long. We start watching the pirate when he is at the dock-end of the plank. If he takes more than 2 step left or right, he falls into the water and drowns. If he takes more than 15 steps forward, he will safely reach his ship.
Write a computer program to simulate the pirate’s drunken stagger as follows:
Read an integer from the user.
The simulation will stop when:
the user enters a negative number. (The pirate presumably falls asleep on the dock).
The pirate falls off the gangplank and drowns.
The pirate makes it safely to his ship.
Display the pirate’s progress after each step.