Drunken Pirate

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.

Repeat

  • 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:

  1. The user enters a negative number. (The pirate presumably falls asleep on the dock).
  2. The pirate falls off the gangplank and drowns.
  3. The pirate makes it safely to his ship.

Display the pirate’s progress after each step.

Credit Blundell@MonktonCoombe

IMAGE CREDIT: https://www.seaofthieves.com/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.