x * y = z where x, y, and z are positive integers with x smaller than y.
The combined digits of x,y,z includes each of the 10 digits exactly once.
What constraints are there on the magnitudes of x and y?
List all solutions for (x,y,z).
Bonus. For which two solutions is the sum (x+y) the same, and what is the value of that sum?
note: no leading zeros
clearvars,clc
ns=perms('0123456789');
for p=1:length(ns)
n0=ns(p,:);
for px=1:4
xs=n0(1:px);
if xs(1)~='0'
x=str2double(xs);
lx=length(xs);
rest=n0(px+1:end);
for py=lx:length(rest)/2
ys=rest(1:py);
ly=length(ys);
if ys(1)~='0'
y=str2double(ys);
zs=rest(py+1:end);
if length(zs)<lx+ly-1
break
end
if zs(1)~='0'
z=str2double(zs);
if x*y==z
fprintf('%4d %6d %9d\n',x,y,z)
end
end
end
end
end
end
end
finds the set
x y z
7 9403 65821
7 9304 65128
78 345 26910
7 4093 28651
7 3094 21658
6 5817 34902
63 927 58401
54 297 16038
52 367 19084
4 9127 36508
4 7039 28156
46 715 32890
45 396 17820
4 3907 15628
39 402 15678
3 9168 27504
3 8169 24507
3 6918 20754
3 6819 20457
36 495 17820
3 5694 17082
27 594 16038
When a file is created and read by
fid=fopen('c:\VB5 Projects\flooble\multiplication includes all digits.txt','r');
t=double.empty(0,4);
while ~feof(fid)
l=fgetl(fid);
x=str2double(l(2:4));
y=str2double(l(8:11));
z=str2double(l(17:21));
disp([x y z])
t(end+1,:)=[x,y,z,x+y];
end
fclose('all');
sortrows(t,4)
the sorted (by sum x+y) list comes out:
x y z x+y
54 297 16038 351
52 367 19084 419
78 345 26910 423
45 396 17820 441
39 402 15678 441
36 495 17820 531
27 594 16038 621
46 715 32890 761
63 927 58401 990
7 3094 21658 3101
4 3907 15628 3911
7 4093 28651 4100
3 5694 17082 5697
6 5817 34902 5823
3 6819 20457 6822
3 6918 20754 6921
4 7039 28156 7043
3 8169 24507 8172
4 9127 36508 9131
3 9168 27504 9171
7 9304 65128 9311
7 9403 65821 9410
The sum 441 appears twice.
|
Posted by Charlie
on 2024-02-16 10:07:34 |