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.
- If the integer is divisible by 2, the pirate takes a step forward.
- If the integer is not divisible by 2, but the integer minus 1 IS divisible by 4, the pirate takes a step to the right.
- Otherwise the pirate steps to the left.
- The computer must randomly pick another number in the range 1 to 100.
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.