Murder occurred one evening in the home of a married couple Mr. Hahn and Mrs. Hahn and their son Oliver and their daughter Claire. One member of the family murdered another member, the third member witnessed the crime, and the fourth member was an accessory after the fact.
- The accessory and the witness were of the opposite sex.
- The oldest member and the witness were of the opposite sex.
- The youngest member and the victim were of the opposite sex.
- The accessory was older than the victim.
- Mr. Hahn was the oldest member.
- The killer was not the youngest member.
From the above clues, determine which one of the four – Mr. Hahn, Mrs. Hahn, Oliver or Claire - was the killer?
DECLARE FUNCTION cap! (x$)
DECLARE SUB permute (a$)
a$ = "HwOc": h$ = a$ ' order murderer, victim, witness, accessory
age$ = "HwOc": hage$ = age$ ' young to old
good = 1
IF INSTR(age$, "H") < INSTR(age$, "O") OR INSTR(age$, "w") < INSTR(age$, "O") THEN good = 0
IF INSTR(age$, "H") < INSTR(age$, "c") OR INSTR(age$, "w") < INSTR(age$, "c") THEN good = 0
IF RIGHT$(age$, 1) <> "H" THEN good = 0
IF good THEN
IF INKEY$ = CHR$(27) THEN STOP
m$ = MID$(a$, 1, 1)
v$ = MID$(a$, 2, 1)
w$ = MID$(a$, 3, 1)
ac$ = MID$(a$, 4, 1)
good = 1
IF cap(ac$) = cap(w$) THEN good = 0
IF cap(w$) THEN good = 0
y$ = LEFT$(age$, 1)
IF cap(y$) = cap(v$) THEN good = 0
IF INSTR(age$, ac$) < INSTR(age$, v$) THEN good = 0
IF LEFT$(age$, 1) = m$ THEN good = 0
IF good THEN PRINT a$, age$
LOOP UNTIL a$ = h$
LOOP UNTIL age$ = hage$
FUNCTION cap (x$)
IF UCASE$(x$) = x$ THEN cap = 1: ELSE cap = 0
(in the above, upper case initials are capital for male and lower case for female; H and w represent husband and wife.)
the wife was the murderer
Oliver was the victim
Claire was the witness
the husband was the accessory
from youngest to oldest: Clair, Oliver, the wife, the husband.
First puzzle done on new Windows 7 machine (previously on XP). Needed to use DOSbox, which is 20 to 25 times as slow as running natively on Command Prompt in XP; but the short permutations here did not need a lot of speed. Permutations of 10 characters takes "forever". Such will need QB64, which is not so good at debugging. Come to think of it DOSbox doesn't allow interrupting a running program manually, even though it does allow setting breakpoints in the program.
Posted by Charlie
on 2014-04-09 14:40:09