Search

 
Problem Description
Two little puzzles involving the number 3:
 Find all 5 digit numbers that contain
the same 5 digits when they are multiplied by 3.

 Find the all of the 3 digit numbers, N,
which together with 2*N and 3*N contain the
digits 1 through 9 exactly once. 
Background & Techniques
The 1st puzzle has been sitting completed in my future projects file for
a year or so. Yesterday's Mensa PuzzleADay calendar had a 2nd "three
related" puzzle so I decided to combine them into a single program.
I'm not sure that it is feasible to solve the 1st puzzle involving 5
digit numbers with pencil and paper, but the 2nd puzzle almost certainly is
if we apply some rules to reduce the search space. For example,

3 times N must be a three digit number
since there can only be 9 digits altogether so N must be less than
333. So the 1st digit of the number must be 1, 2, or 3.


If N starts with 1, then 2*N
will start with 2, or 3 and 3*N will start with 3, 4, or 5 since
there can be no carry greater than 1 or 2. Similar
restrictions for 2*N and 3*N if N starts with 2 or 3.


The last digit cannot be 5 or else 3
times the number would also end in 5. 

There can be no zeros anywhere.


If we choose a trial units digit, we
know the units digits for all 3 numbers which greatly reduces the
possibilities for the 10's digit. 

Etc. 
I did not solve it manually, but believe I could have  it was just
more fun to write the code to let the computer do the grunt work.
J
Nonprogrammers are welcome to read on, but may
want to skip to the bottom of this page to download
executable version of the program.
Notes for Programmers
The fist problem, find N and 3*N with 5 digits and containing the same
digits is simple once we have the SortDigits procedure; simply
sort the digits of i and 3*i for numbers in the range of 10000 (the smallest
5 digit number) and 33333 (the largest with 3*i still containing only 5
digits). SortDigits returns the digits of an input integer
as a new integer with the digits in sorted sequence. First we split
out the digits of the input number into an integer array with one digit in
each location (6 lines of code). Then we sort the array in increasing
sequence (3 lines of code). then we rebuild the sorted digit array as
a single integer (2 lines of code) and return it as the result.
Version 2, The generalized version of Problem 1, is slightly more
complicated, but uses exactly the same algorithm as Version 1.
Problem 2, a three digit number combined with double and triple
the number will contain digits 1 to 9 exactly one time each is also not too
hard. The trick is to separate out the digits of i, 2*i
and 3*i into an array and somehow make that all of the digits 1 to 9
are found and that no digit occurs more than one time. I settled on
using a 9 character string, DigitCheck, initialized to "NNNNNNNNN"
for each value to be tested. Then when we check the digits, a 1
will replace the "N" with "Y" in DigitCheck[1],
etc. One additional check makes sure that an "N" is in a
position before placing the 'Y" there  this implies that this
is the first occurrence of that digit. If it is not "N" then
we'll put an "X" there. All of this happens in a local
function named Check. Afterr calling Check with
i, 2*i and 3*i, we have found a solution if DigitCheck="YYYYYYYYY".
Running/Exploring the Program
Suggestions for Further Explorations
I believe that, if the restriction of "exactly" one
occurrence of 19 in Problem 2 is removed, a few more solutions with 10
digits would be found where one of the digits occurs more than once.
Original Date: May 26, 2009 
Modified:
May 15, 2018 

