Mr. and Mrs. Astor, Mr. and Mrs. Blake, Mr. and Mrs. Crane, and Mr. and Mrs. Davis were seated around a table as shown:
+---+
| 1 |
+---+ +---+ +---+
| 8 | | 2 |
+---+ +---+
+---+ +---+
| 7 | o | 3 |
+---+ +---+
+---+ +---+
| 6 | | 4 |
+---+ +---+ +---+
| 5 |
+---+
1) Mrs. Astor was insulted by Mr. Blake who sat next to her on her left.
2) Mr. Blake was insulted by Mrs. Crane who sat opposite him across the center of the table.
3) Mrs. Crane was insulted by the hostess who was the only person who sat between a married couple.
4) The hostess was insulted by the only person who sat between two men.
Who insulted the hostess?
Denoting the men with capital letters and women with lower case, the seating sequence, hostess and insulter of the hostess were:
BadAcbDC
hostess was d
C (between D and B) insulted the hostess
found by the program:
DECLARE SUB permute (a$)
CLS
a1$ = "AbCDd": h$ = a1$
DO
a$ = RIGHT$(a1$, 1) + "Ba" + LEFT$(a1$, 2) + "c" + RIGHT$(a1$, 3) + "B"
' last repeated at beginning and first at end to provide neighbors
btwnMarried = 0: btwnMen = 0
FOR i = 1 TO 8 ' person at i+1; neighbors at i and i+2
n1$ = MID$(a$, i, 1)
n2$ = MID$(a$, i + 2, 1)
IF LCASE$(n1$) = LCASE$(n2$) THEN
btwnMarried = btwnMarried + 1: bMrd$ = MID$(a$, i + 1, 1)
END IF
IF UCASE$(n1$) = n1$ AND UCASE$(n2$) = n2$ THEN
btwnMen = btwnMen + 1: bMen$ = MID$(a$, i, 3)
END IF
NEXT
IF btwnMarried = 1 AND btwnMen = 1 THEN
IF bMrd$ <> "c" AND LCASE$(bMrd$) = bMrd$ THEN
hsts$ = bMrd$
PRINT MID$(a$, 2, 8)
PRINT "hostess was "; hsts$
PRINT MID$(bMen$, 2, 1); " (between "; LEFT$(bMen$, 1); " and "; RIGHT$(bMen$, 1); ") ";
PRINT " insulted the hostess"
PRINT
END IF
END IF
permute a1$
LOOP UNTIL a1$ = h$
The permute subroutine is elsewhere on the site.
|
Posted by Charlie
on 2005-10-25 11:16:24 |