No matter how we permute the 3 digits 1,2 4 ,
none of the 6 three- digit numbers (124,142,214,241,412,421) is a multiple of 7.
Clearly, out of 84 possible triplets created by choosing distinct non-zero digits
there must be several like this, i.e. generating a 6-pack of three-digit numbers,
non divisible by 7.
1. List those triplets.
2. Similar question re:4 digits and divisibility by 23.
Part 1:
DEFDBL A-Z
CLS
FOR a = 1 TO 7
FOR b = a + 1 TO 8
FOR c = b + 1 TO 9
n1 = a * 100 + b * 10 + c
n2 = a * 100 + c * 10 + b
n3 = b * 100 + a * 10 + c
n4 = b * 100 + c * 10 + a
n5 = c * 100 + b * 10 + a
n6 = c * 100 + a * 10 + b
IF n1 MOD 7 > 0 THEN
IF n2 MOD 7 > 0 THEN
IF n3 MOD 7 > 0 THEN
IF n4 MOD 7 > 0 THEN
IF n5 MOD 7 > 0 THEN
IF n6 MOD 7 > 0 THEN
PRINT a; b; c
END IF
END IF
END IF
END IF
END IF
END IF
NEXT
NEXT
NEXT
finds
1 2 4
1 2 5
1 2 9
1 3 6
1 3 8
1 4 6
1 4 8
1 4 9
1 5 9
1 6 7
1 7 8
2 3 4
2 4 8
2 5 6
2 5 7
2 5 8
2 6 9
2 7 9
2 8 9
3 4 5
3 4 7
3 4 9
3 5 6
3 6 8
4 6 8
4 8 9
5 6 9
5 7 9
5 8 9
6 7 8
Part 2:
DECLARE SUB permute (a$)
DEFDBL A-Z
CLS
FOR a = 1 TO 6
FOR b = a + 1 TO 7
FOR c = b + 1 TO 8
FOR d = c + 1 TO 9
n$ = LTRIM$(STR$(a)) + LTRIM$(STR$(b)) + LTRIM$(STR$(c)) + LTRIM$(STR$(d))
h$ = n$
good = 1
DO
n = VAL(n$)
IF n MOD 23 = 0 THEN good = 0: EXIT DO
permute n$
LOOP UNTIL n$ = h$
IF good THEN PRINT a; b; c; d
NEXT
NEXT
NEXT
NEXT
(Listing for permute shown elsewhere on Perplexus.)
finding:
1 2 3 4
1 2 3 5
1 2 3 6
1 2 3 7
1 2 4 9
1 2 6 7
1 2 6 8
1 2 7 8
1 3 4 9
1 3 5 6
1 3 5 8
1 3 7 8
1 3 8 9
1 4 5 8
1 4 8 9
1 5 6 7
1 5 6 9
1 5 7 9
1 6 8 9
2 3 4 9
2 3 5 7
2 3 5 9
2 3 7 9
2 4 5 9
2 4 6 7
2 4 6 8
2 5 6 9
2 5 8 9
2 6 8 9
2 7 8 9
3 4 5 6
3 4 5 7
3 4 6 7
3 5 6 8
3 5 7 8
3 7 8 9
4 5 6 7
4 5 6 9
4 5 7 8
4 5 8 9
If the second part had stuck with 7, instead of 23, we'd have the more exclusive:
1 2 3 8
1 3 8 9
2 4 6 9
|
Posted by Charlie
on 2010-11-08 16:22:21 |