+----+---------+----+---------+
| 1 | | | 5 |
+----+ | 4 +---------+
| 2 | 3 | | 6 |
+----+ +----+---------+
| | | east |
| +---------+ +---------+
| west | | |
+----+----+----+----| 10 |
| | | south | |
| | +----+ +----+----+
| 7 | 8 | | | | |
| | | 9 | | 11 | 12 |
| | | | | | |
+----+----+----+----+----+----+
The plan above shows an arrangement of corn, wheat and rye fields. Jack
is in the middle of one of the fields and has to meet his father in the
middle of another field.
On his journey from the field he is in to the field his father is in.
- His route takes him continuously through each of five other fields exactly once.
- He (being allergic to rye) avoids going through any part of a rye field.
- He notices no two fields of the same kind border on each other.
Which L-shaped field - east, west, or south- is a rye field?
Preliminary setup: the fields have types matching field 1, 2 or 3, forced by proximity to two other types (crop) of field:
West: type 1
East: type 2
4: type 1
6: type 3
5: type 2
South: type 3
10: type 1 (designated field a below)
11: type 2 (designated field b below)
12: type 3 (designated field c below)
8: type 2
9: type 1
7: type 3
The program uses 1-character names for each field: 1 - 9 for fields 1 - 9; a - c for 10 - 12; and w,s and e for west, south and east. They are typed according to their crop content's being the same as field 1, 2 or 3.
DECLARE SUB addOn ()
DECLARE FUNCTION subscr! (nam$)
CLEAR , , 25000
DIM SHARED seq$, conn$(15), typ(15), path$, avoid
seq$ = "123456789abcwse"
DATA 23,13w,12we4,3e65,46,54e,w8,7ws9,8s,esbc,as,ab,23es87,98weab,643wsa
FOR i = 1 TO 15: READ conn$(i): NEXT
DATA 1,2,3,1,2,3,3,2,1,1,2,3,1,3,2
FOR i = 1 TO 15: READ typ(i): NEXT
CLS
FOR startpos = 1 TO 15
FOR avoid = 1 TO 3
path$ = MID$(seq$, startpos, 1)
IF typ(subscr(path$)) <> avoid THEN
addOn
END IF
NEXT
NEXT
SUB addOn
s = subscr(RIGHT$(path$, 1))
choice$ = conn$(s)
FOR i = 1 TO LEN(choice$)
newfield$ = MID$(choice$, i, 1)
s2 = subscr(newfield$)
IF typ(s2) <> avoid THEN
IF INSTR(path$, newfield$) = 0 THEN
path$ = path$ + newfield$
IF LEN(path$) = 7 THEN
PRINT path$, avoid
ELSE
addOn
END IF
path$ = LEFT$(path$, LEN(path$) - 1)
END IF
END IF
NEXT
END SUB
FUNCTION subscr (nam$)
subscr = INSTR(seq$, nam$)
END FUNCTION
finds
643wsac 2
casw346 2
indicating the sequence of fields from start to finish, and that the type field being avoided is the same as the content of field 2. As the East field has that content, that is the field that has rye.
|
Posted by Charlie
on 2013-03-11 12:00:53 |