164
758
932
and its rotations and reflections.
The numbers are
164 758 932 179 653 482 461 857 239 971 356 284
Six of these are divisible by 2 and four are divisible by 4. Zero are divisible by 3, 5, 6, 7, 8 or 9. Of course all twelve are divisible by 1.
DECLARE SUB permute (a$)
DIM n(12)
CLS
s$ = "123456789": h$ = s$
DO
n(1) = VAL(LEFT$(s$, 3))
n(2) = VAL(MID$(s$, 4, 3))
n(3) = VAL(RIGHT$(s$, 3))
n(4) = VAL(MID$(s$, 1, 1) + MID$(s$, 4, 1) + MID$(s$, 7, 1))
n(5) = VAL(MID$(s$, 2, 1) + MID$(s$, 5, 1) + MID$(s$, 8, 1))
n(6) = VAL(MID$(s$, 3, 1) + MID$(s$, 6, 1) + MID$(s$, 9, 1))
FOR i = 1 TO 6
nm$ = LTRIM$(STR$(n(i)))
n0 = 0
FOR j = 3 TO 1 STEP -1
n0 = n0 * 10 + VAL(MID$(nm$, j, 1))
NEXT
n(i + 6) = n0
NEXT i
good = 1
FOR div = 2 TO 9
t = 0
FOR i = 1 TO 12
r = n(i) MOD div
IF r = 0 THEN t = t + 1
NEXT
r = t MOD div
IF r > 0 THEN good = 0: EXIT FOR
NEXT
IF good THEN
FOR i = 1 TO 12
PRINT USING " ###"; n(i);
NEXT
PRINT
FOR div = 2 TO 9
t = 0
FOR i = 1 TO 12
r = n(i) MOD div
IF r = 0 THEN t = t + 1
NEXT
PRINT t;
NEXT
PRINT
PRINT MID$(s$, 1, 3)
PRINT MID$(s$, 4, 3)
PRINT MID$(s$, 7, 3)
PRINT
END IF
permute s$
LOOP UNTIL s$ = h$
which produces
164 758 932 179 653 482 461 857 239 971 356 284
6 0 4 0 0 0 0 0
164
758
932
179 653 482 164 758 932 971 356 284 461 857 239
6 0 4 0 0 0 0 0
179
653
482
239 857 461 284 356 971 932 758 164 482 653 179
6 0 4 0 0 0 0 0
239
857
461
284 356 971 239 857 461 482 653 179 932 758 164
6 0 4 0 0 0 0 0
284
356
971
461 857 239 482 653 179 164 758 932 284 356 971
6 0 4 0 0 0 0 0
461
857
239
482 653 179 461 857 239 284 356 971 164 758 932
6 0 4 0 0 0 0 0
482
653
179
932 758 164 971 356 284 239 857 461 179 653 482
6 0 4 0 0 0 0 0
932
758
164
971 356 284 932 758 164 179 653 482 239 857 461
6 0 4 0 0 0 0 0
971
356
284
showing all rotations and reflections, with the numbers and the number of divisibilities by 2 through 9.
From Enigma No. 1463 by Susan Denham, New Scientist, 6 October 2007. |