The teacher has recently set a class the following puzzle: "Write down four positive whole numbers less than 100 and then write down their average: choose the original numbers so that overall the five numbers written down use each of the digits 1 to 9 exactly once."
Three students in the class were successful. Heinrich came up with 9, 15, 36 and 48, with average 27. Felix was more cunning – his average was not a whole number – it involved a mixed fraction in its simplest form, like 27¾. Delphine was devious, too, and her average, which was lower than Felix's, was not a whole number – it involved decimals, like 16.25.
What averages did Felix and Delphine write?
clearvars
for a=1:99
as=char(string(a));
asy=sym(a);
for b=a+1:99
bs=char(string(b));
bsy=sym(b);
for c=b+1:99
cs=char(string(c));
csy=sym(c);
for d=c+1:99
ds=char(string(d));
dsy=sym(d);
s=[as bs cs ds];
if length(s)==length(unique(s))
avgsym=sum([asy bsy csy dsy])/sym(4);
avgstr=char(avgsym);
idx=false;
if contains(avgstr,'/')
idx=true;
[num,den]=numden(avgsym);
q=floor(num/den); rem=num-q*den;
avgstr=[char(string(q)) char(string(rem)) char(string(den))];
end
s=[as bs cs ds avgstr];
dgts=s;
avg=mean([a b c d]);
if length(dgts)==9 && length(unique(dgts))==9
if isempty(find(dgts=='0')) && idx==true
fprintf('%d %d %d %d %d %d/%d %f\n', a,b,c,d,q,rem,den,avg)
end
end
avgs=char(string(avg));
idx=find(avgs=='.');
if ~isempty(idx)
avgs(idx)='';
dgts=[as bs cs ds avgs];
if length(dgts)==9 & length(unique(dgts))==9
if isempty(find(dgts=='0'))
fprintf('%d %d %d %d %f\n',a,b,c,d,avg)
end
end
end
end
end
end
end
end
finds these possibilities:
Each line shows the four numbers followed by their average, either in decimal fraction form or mixed fraction form. If the latter, it also shows the decimal form. Disregard the trailing zeros.
1 3 6 89 24.750000
1 3 9 86 24.750000
1 6 7 89 25 3/4 25.750000
1 6 9 83 24.750000
1 6 9 87 25 3/4 25.750000
1 7 9 86 25 3/4 25.750000
2 7 48 69 31.500000
2 7 49 68 31.500000
2 8 47 69 31.500000
2 8 49 67 31.500000
2 9 47 68 31.500000
2 9 48 67 31.500000
3 6 9 81 24.750000
4 6 27 89 31.500000
4 6 29 87 31.500000
4 7 26 89 31.500000
4 7 29 86 31.500000
4 9 26 87 31.500000
4 9 27 86 31.500000
6 7 9 81 25 3/4 25.750000
6 7 24 89 31.500000
6 7 29 84 31.500000
6 9 24 87 31.500000
6 9 27 84 31.500000
7 8 42 69 31.500000
7 8 49 62 31.500000
7 9 24 86 31.500000
7 9 26 84 31.500000
7 9 42 68 31.500000
7 9 48 62 31.500000
8 9 42 67 31.500000
8 9 47 62 31.500000
The results show that Delphine could have had 24.75 or 31.5 as an average, while Felix could have had only 25 3/4. Since Delphine's was lower than Felix's, Delphine's was 24.75.
|
Posted by Charlie
on 2023-10-07 09:41:15 |