Conway Digital Perfection from Quanta

  • Thread starter Deleted member 4993
  • Start date
D

Deleted member 4993

Guest
Puzzle 1: Digital Perfection
There is a mysterious 10-digit decimal number, abcdefghij. Each of the digits is different, and they have the following properties:
  • a is divisible by 1
  • ab is divisible by 2
  • abc is divisible by 3
  • abcd is divisible by 4
  • abcde is divisible by 5
  • abcdef is divisible by 6
  • abcdefg is divisible by 7
  • abcdefgh is divisible by 8
  • abcdefghi is divisible by 9
  • abcdefghij is divisible by 10

What’s the number?
I do not know the answer yet - working on it. It is one of the Conway puzzles.
 
This puzzle is all about divisibility, and Wikipedia has a handy reference for divisibility rules for small numbers.

I don't know the full answer, but I can make some observations...
  • j is 0, since a number that is divisible by 10 must end in 0.
  • e is 5, since a number that is divisible by 5 must end in 0 or 5, and 0 already belongs to j.
  • b, d, f and h are all even digits, since only even numbers are divisible by even numbers.
  • a, c, g and i are likewise odd digits, since all even digits are accounted for by other letters.
At this point I got tired of thinking about it and drafted up some JavaScript to brute force it:
JavaScript:
// Calculate a permutation of an arbitrary number of items
function permutation(numItems, n) {

    // Produce a list of items and count the total number of permutations
    let items = [];
    let perms = 1;
    for (let item = 0; item < numItems; item++) {
        items.push(item);
        perms *= item + 1;
    }

    // The requested permutation is out of range
    if (n >= perms)
        return null;

    // Select the items for the current permutation
    let perm = [];
    for (let item = 0; item < numItems; item++) {
        let segment = perms / (numItems - item);
        perm.push(items.splice(Math.floor(n / segment), 1)[0]);
        n     %= segment;
        perms /= numItems - item;
    }
    return perm;
}

// Test if the nth assortment of digits solves the puzzle
function testNumber(n) {

    // Calculate the permutation sequence
    var perm = permutation(10, n);
    if (!perm)
        return null;

    // Check all 10 digits of the number
    let number = 0;
    let digit  = 0;
    for (; digit < 10; digit++, number *= 10) {

        // Build the number starting from the "left" digit
        number += perm[digit];

        // Test if the digit solves the puzzle
        if (number % (digit + 1) != 0)
            break;
    }

    return digit == 10 ? number / 10 : 0;
}

// Test all 10-digit numbers (with unique digits) against the puzzle
for (let n = 0;; n++) {

    // Test the nth permutation
    let number = testNumber(n);

    // No more permutations
    if (number === null)
        break;

    // The number solves the puzzle
    if (number)
        console.log(("0" + number).slice(-10));
}
Running the code shows that there is only one such number that solves the puzzle. Neat!
 
abc is divisible by 3. Post#2 says a and c are odd, but b is even therefore a+b+c is even. Combine this with "casting out threes" and we have
a+b+c = 6*n, integer n

--

abcd is divisible by 4. Therefore cd is divisible by 4. But post#2 says c is odd, and this further implies
d=2 or 6

--

abcdef
is divisible by 6. Using the "parities" in post#2 says a+b+c+d+5+f is odd. Casting out threes:-
a+b+c+d+5+f = 3 + 6*m, integer m
a+b+c+d+f = -2 + 6*m
Using the "abc is divisible by 3" result gives
6*n+d+f = -2 + 6*m
d+f = -2 + 6*<some integer>
d+f=4, 10, or 16. Combine this with "abcd is divisible by 4" result that says d=2 or 6 then
d+f=10
 
Hi All,

Here is my solution using the language system verilog

class perfect_num;

rand byte unsigned a,b,c,d,e,f,g,h;
constraint perf_num {
((a%1)) == 0;
((10*a+b)%2) ==0;
((100*a+10*b+c)%3) ==0;
((1000*a+100*b+10*c+d)%4==0);
((10000*a+1000*b+100*c+10*d+e) % 5) == 0; a<=9;b<=9;c<=9;d<=9;e<=9;
}
constraint uq {unique{a,b,c,d,e};}
endclass


If any one interested an run the above code at the following link

 
Top