Given a clock, rearrange six consecutive numbers on its face, so
the sum of every pair of adjacent numbers is a prime.
The following program cycles which 6 in a row are scrambled and goes through all 720 permutations of each six:
DECLARE SUB permute (a$)
CLS
FOR i = 1 TO 12
face$ = face$ + CHR$(i)
NEXT
h$ = face$
prime(1) = 2
prime(2) = 3
prime(3) = 5
prime(4) = 7
prime(5) = 11
prime(6) = 13
prime(7) = 17
prime(8) = 19
prime(9) = 23
DO
h2$ = face$
DO
good = 1
f$ = face$ + LEFT$(face$, 1)
FOR i = 1 TO 12
p = ASC(MID$(f$, i, 1)) + ASC(MID$(f$, i + 1, 1))
hit = 0
FOR j = 2 TO 9
IF p = prime(j) THEN hit = 1: EXIT FOR
NEXT
IF hit = 0 THEN good = 0: EXIT FOR
NEXT
IF good THEN
FOR i = 1 TO 12
PRINT ASC(MID$(f$, i, 1));
NEXT
PRINT
END IF
t$ = LEFT$(face$, 6)
permute t$
MID$(face$, 1, 6) = t$
LOOP UNTIL face$ = h2$
face$ = MID$(face$, 2) + LEFT$(face$, 1)
LOOP UNTIL h$ = face$
where the subroutine permute is shown elsewhere on this site.
The findings were
7 10 9 8 5 6 11 12 1 2 3 4
9 10 7 6 5 8 11 12 1 2 3 4
Shown starting at 1, that's
1 2 3 4 7 10 9 8 5 6 11 12 and
1 2 3 4 9 10 7 6 5 8 11 12
In one instance the 8, among the 6 rearranged numbers, is in its own position, and in the other the 7, also among the rearranged numbers, is in its own position.
|
Posted by Charlie
on 2004-08-01 11:29:46 |