We have these digits : $1,2,3,4,5,6,7,8,9$. Using these digits, we have to make two numbers such that their product must be as large as possible. We have to use all digits only once.
I did $97531\times 8642$ and got $842862902$
We have these digits : $1,2,3,4,5,6,7,8,9$. Using these digits, we have to make two numbers such that their product must be as large as possible. We have to use all digits only once.
I did $97531\times 8642$ and got $842862902$
On
I got a bigger one : $87531\times 9642=843973902$
What I did was start with two blanks. Then I started putting the greater digits one by one, keeping the sum of digits of both the number somewhat balanced. The greater digits are given more preference, by putting them at a greater place value.
On
$87531 \cdot 9642 = 843973902$
I could confirm imakesmalltalk's answer by a JavaScript program.
Install node.js, execute node the-saved-script-name.js and the last line from the program's output should be the largest possible product.
The program should run reasonably fast, it needs 3.936 seconds on my PC.
/* Create all given permutations of an array
* @author Oriol <http://stackoverflow.com/users/1529630/oriol
* @link http://stackoverflow.com/a/11509565/603003
* @license CC BY-SA 3.0 with attribution required
*/
function permute(input) {
var permArr = [],
usedChars = [];
function main(){
var i, ch;
for (i = 0; i < input.length; i++) {
ch = input.splice(i, 1)[0];
usedChars.push(ch);
if (input.length == 0) {
permArr.push(usedChars.slice());
}
main();
input.splice(i, 0, ch);
usedChars.pop();
}
return permArr;
}
return main();
}
var numbers = [1,2,3,4,5,6,7,8,9];
var maxProduct = 0;
permute(numbers).forEach(function (permutation) {
for (var i=1; i<9; i++) {
var factor1 = parseInt(permutation.slice(0, i).join(""), 10);
var factor2 = parseInt(permutation.slice(i, permutation.length).join(""), 10);
var product = factor1 * factor2;
if (product > maxProduct) {
maxProduct = product;
console.log("New maxProduct: " + maxProduct + " (factor1: " + factor1 + ", factor2: " + factor2 + ")");
}
}
});
Output:
...
the last line follows:
New maxProduct: 843973902 (factor1: 87531, factor2: 9642)
Note that if $a\gt b$ and $c\gt 0$ then $(10a+b)c\gt (10b+a)c$ - so we can organise the two numbers so that the largest digits are in the places of highest significance.
If the two numbers we are multiplying have $m$ and $n$ digits their product is less than $10^m\times 10^n=10^{m+n}=10^9$ so the product must have at most nine digits, and since nine digits is possible, the largest product will have nine digits.
Work down from the most significant digits.
$9\times 8=72$
Now we place $7$ and since $7\times 9\gt 7\times 8$ we choose $9\times 87$.
Next $6$ has to be allocated. It occupies a more significant place (second) if we have $96\times 87$ than $9\times 876$ where it is third - check $8352\gt 7884$.
Now $5$ goes in the most significant place it can, and since both are equal, it goes where it is multiplied by the highest number i.e. $96\times 875$
Continuing we get $9642\times87531=843,973,902$
@imakesmalltalk got there first, but this explanation was too long for a comment.