Skip to content

Instantly share code, notes, and snippets.

@emhoracek
Created May 14, 2016 13:38
Show Gist options
  • Save emhoracek/a03208b2083d8b2c6d181f73be484370 to your computer and use it in GitHub Desktop.
Save emhoracek/a03208b2083d8b2c6d181f73be484370 to your computer and use it in GitHub Desktop.
The murder at the Metropolitan Club
program METROPOLITANCLUB (output);
{ -- This programme examines the clues given for the murder at
-- the Metropolitan Club. The three arrays HAIR, ATTIRE, and
-- ROOM are used to establish the facts as they are determined.
-- The programme outputs the name of the murderer. }
const
UNKNOWN = 0;
RED = 1; BLACK = 2; GREY = 3; BROWN = 4;
PINCENEZ = 1; GOLDWATCH = 2; RUBYRING = 3; TATTEREDCUFFS = 4;
COLWOODLEY = 1; MRHOLMAN = 2; MRPOPE = 3; SIRRAYMOND = 4;
var
SUSPECT, MURDERER : INTEGER;
HAIR : array [ COLWOODLEY..SIRRAYMOND ] of INTEGER;
ATTIRE : array [ COLWOODLEY..SIRRAYMOND ] of INTEGER;
ROOM : array [ COLWOODLEY..SIRRAYMOND ] of INTEGER;
begin
{ -- Assume nothing is known. }
MURDERER := UNKNOWN;
for SUSPECT := COLWOODLEY to SIRRAYMOND do begin
HAIR[SUSPECT] := UNKNOWN;
ATTIRE[SUSPECT] := UNKNOWN;
ROOM[SUSPECT] := UNKNOWN;
end;
{ -- Establish known clues. }
ROOM[SIRRAYMOND] := 10;
ATTIRE[MRPOPE] := GOLDWATCH;
ATTIRE[MRHOLMAN] := RUBYRING;
ROOM[MRHOLMAN] := 12;
{ -- Repeatedly try remaining clues. }
SUSPECT := COLWOODLEY;
while MURDERER = UNKNOWN do begin
if (ROOM[SUSPECT] = 14) then
HAIR[SUSPECT] := BLACK;
if (ATTIRE[SIRRAYMOND] <> UNKNOWN) and
(ATTIRE[SIRRAYMOND] <> PINCENEZ) then
ATTIRE[COLWOODLEY] := PINCENEZ;
if (ATTIRE[COLWOODLEY] <> UNKNOWN) and
(ATTIRE[COLWOODLEY] <> PINCENEZ) then
ATTIRE[SIRRAYMOND] := PINCENEZ;
if (ATTIRE[SUSPECT] = PINCENEZ) then
HAIR[SUSPECT] := BROWN;
if (ATTIRE[SUSPECT] = TATTEREDCUFFS) then
HAIR[SUSPECT] := RED;
if (ROOM[SUSPECT] = 16) then
ATTIRE[SUSPECT] := TATTEREDCUFFS;
if (ROOM[SUSPECT] = 12) then
HAIR[SUSPECT] := GREY;
if (ATTIRE[SUSPECT] = GOLDWATCH) then
ROOM[SUSPECT] := 13;
if (ROOM[SUSPECT] = 10) and (SUSPECT <> COLWOODLEY) then
ROOM[COLWOODLEY] := 16;
if (ROOM[SUSPECT] = 16) and (SUSPECT <> COLWOODLEY) then
ROOM[COLWOODLEY] := 10;
if (HAIR[SUSPECT] = BROWN) then
MURDERER := SUSPECT;
if (SUSPECT = SIRRAYMOND) then
SUSPECT := COLWOODLEY
else
SUSPECT := SUSPECT + 1
end; { -- remaining clues }
{ -- Reveal the name of the murderer. }
if (MURDERER = COLWOODLEY) then
WRITE('THE MURDERER IS COLONEL WOODLEY.')
else if (MURDERER = MRHOLMAN) then
WRITE('THE MURDERER IS MR HOLMAN.')
else if (MURDERER = MRPOPE) then
WRITE('THE MURDERER IS MR POPE.')
else
WRITE('THE MURDERER IS SIR RAYMOND.')
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment