Post Reply 
Mini-challenge: digits by half
03-29-2022, 12:42 PM
Post: #5
RE: Mini-challenge: digits by half
Nice solutions, Albert and Alan. I, too, was surprised to find multiple answers.

My approach is similar to Albert's. Using his notation (6ABC * 2 = 1DEFG), it's clear that D is 2 or 3. Next I used the fact that the least significant N digits of 1DEFG are fully determined by the least significant N digits of 6ABC * 2. This leads to C being 2,4,7 or 9.

Then I figured the possibilities for the least significant 2 digits. I don't have my notes in front of me, but I think that led to 4 dropping out as a candidate for C

Moving to the least significant 3 gave the answer. A simple C++ program gives them all:
Code:
#include <iostream>

int digits(int num)
{
    int result = 0;
    div_t divRes;
    while(num) {
        divRes = div(num, 10);
        result |= 1<< divRes.rem;
        num = divRes.quot;
    }
    return result;
}

int
main()
{
    for (int x=1; x < 10000; ++x) {
        if ((digits(x) | digits(2*x)) == (0x3fe)) {
            std::cout << x << ' ' << 2*x << '\n';
        }
    }
}
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Mini-challenge: digits by half - Allen - 03-28-2022, 10:34 PM
RE: Mini-challenge: digits by half - David Hayden - 03-29-2022 12:42 PM



User(s) browsing this thread: 2 Guest(s)