+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| C | D | | I | H | | E | G | | F | B | | E | I |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| B | H | | A | G | | J | C | | D | F | | A | J |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| A | E | | B | G | | H | J | | H | E | | C | B |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| I | G | | C | F | | F | I | | A | D | | D | J |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| G | I | | F | D | | B | E | | H | J | | H | F |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| A | D | | B | E | | C | G | | J | I | | A | C |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| E | F | | I | J | | B | A | | C | G | | D | E |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| F | H | | J | H | | A | D | | G | C | | I | B |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| J | B | | C | D | | F | D | | B | A | | H | G |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| C | J | | E | A | | H | I | | I | E | | G | F |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+
Each of the 25 blocks of four letters shown above can be rotated about its center, either 90
o clockwise, 90
o anti-clockwise or 180
o. When all the blocks are in their correct orientations, all the ten rows and columns contain the letters A to J exactly once.
Sixteen of the blocks shown above are not in their correct orientations. Which 16 out of the 25 blocks have been rotated and in which direction(s)?
DECLARE SUB orient (lv!)
CLEAR , , 25000
OPEN "blockpos.txt" FOR INPUT AS #1
OPEN "block positions.txt" FOR OUTPUT AS #2
OPEN "block positions selected.txt" FOR OUTPUT AS #3
DIM SHARED gr(10, 10) AS STRING, which(16), rot(16), solct, prev1, prev2
DO
LINE INPUT #1, l$
IF INSTR(l$, "--") = 0 THEN
col = 0: row = row + 1
FOR i = 1 TO LEN(l$)
IF INSTR("ABCDEFGHIJ", MID$(l$, i, 1)) > 0 THEN
col = col + 1
gr(row, col) = MID$(l$, i, 1)
PRINT gr(row, col);
END IF
NEXT
PRINT
END IF
LOOP UNTIL EOF(1)
CLOSE 1
FOR st = 1 TO 10
which(1) = st
orient 1
NEXT
PRINT solct
CLOSE 2: CLOSE 3
SUB orient (lv)
col = (which(lv) - 1) MOD 5 + 1
row = (which(lv) - 1) \ 5 + 1
c0 = col * 2 - 1: r0 = row * 2 - 1
FOR rota = 1 TO 4
h$ = gr(r0, c0 + 1)
gr(r0, c0 + 1) = gr(r0, c0)
gr(r0, c0) = gr(r0 + 1, c0)
gr(r0 + 1, c0) = gr(r0 + 1, c0 + 1)
gr(r0 + 1, c0 + 1) = h$
IF rota < 4 THEN
good = 1
FOR c = c0 TO c0 + 1
FOR r = 1 TO r0 - 1
IF gr(r, c) = gr(r0, c) OR gr(r, c) = gr(r0 + 1, c) THEN good = 0: EXIT FOR
NEXT
IF good = 0 THEN EXIT FOR
NEXT
IF good THEN
FOR r = r0 TO r0 + 1
FOR c = 1 TO c0 - 1
IF gr(r, c) = gr(r, c0) OR gr(r, c) = gr(r, c0) THEN good = 0: EXIT FOR
NEXT
IF good = 0 THEN EXIT FOR
NEXT
IF good THEN
rot(lv) = rota
IF lv = 16 THEN
FOR r = 1 TO 10
FOR c1 = 1 TO 9
FOR c2 = c1 + 1 TO 10
IF gr(r, c1) = gr(r, c2) THEN good = 0
NEXT
NEXT
NEXT
FOR c = 1 TO 10
FOR r1 = 1 TO 9
FOR r2 = r1 + 1 TO 10
IF gr(r1, c) = gr(r2, c) THEN good = 0
NEXT
NEXT
NEXT
IF good THEN
FOR r = 1 TO 10
FOR c = 1 TO 10
PRINT gr(r, c);
IF c MOD 2 = 0 THEN PRINT " ";
NEXT
PRINT
IF r MOD 2 = 0 THEN PRINT
NEXT
FOR i = 1 TO lv: PRINT USING "###"; which(i);: NEXT: PRINT
FOR i = 1 TO lv: PRINT USING "###"; rot(i);: NEXT: PRINT
FOR i = 1 TO lv: PRINT #2, USING "###"; which(i);: NEXT: PRINT #2, " ";
FOR i = 1 TO lv: PRINT #2, USING "###"; rot(i);: NEXT: PRINT #2,
PRINT
IF which(1) <> prev1 OR which(2) <> prev2 THEN
prev1 = which(1): prev2 = which(2)
FOR r = 1 TO 10
FOR c = 1 TO 10
PRINT #3, gr(r, c);
IF c MOD 2 = 0 THEN PRINT #3, " ";
NEXT
PRINT #3,
IF r MOD 2 = 0 THEN PRINT #3,
NEXT
FOR i = 1 TO lv: PRINT #3, USING "###"; which(i);: NEXT: PRINT #3,
FOR i = 1 TO lv: PRINT #3, USING "###"; rot(i);: NEXT: PRINT #3,: PRINT #3,
END IF
solct = solct + 1
END IF
ELSE
FOR nxt = which(lv) + 1 TO 26 - 16 + lv
which(lv + 1) = nxt
orient lv + 1
NEXT
END IF
END IF
END IF
END IF
NEXT
END SUB
finds
BC IH EG DF JA
HD AG JC FB IE
IA GF HJ ED CB
GE BC FI HA DJ
AG DE CB IJ HF
DI FB GE JH AC
EF HJ AD CG BI
FH JI BA GC ED
JB CD IH AE FG
CJ EA DF BI GH
1 4 5 6 7 9 11 12 13 14 17 18 20 23 24 25
1 1 2 1 3 3 1 3 1 2 2 3 2 2 3 2
where the next-to-last line indicates which blocks were rotated, where the numeration is in normal reading order: left-to-right within top-to-bottom, and each number on the last line indicates the number of 90° clockwise turns are applied to the block indicated just above it.
|
Posted by Charlie
on 2013-08-19 19:34:12 |