Three friends Ade, Ben and Cade have 9 marbles in front of them. Their weights are as follows:
154, 16, 19, 101, 10, 17, 13, 46 and 22 grams.
Each of the three friends takes 3 marbles. Ade's bunch weighs precisely twice as much as Bill's bunch.
What is the total weight in Cade's bunch?
(In reply to
Computer Program Solution by Larry)
In MATLAB:
marbles=[154, 16, 19, 101, 10, 17, 13, 46, 22];
for i=1:7
a(1)=marbles(i);
for j=i+1:8
a(2)=marbles(j);
for k=j+1:9
a(3)=marbles(k);
m2=marbles;
m2(k)=[];m2(j)=[];m2(i)=[];
for l=1:4
b(1)=m2(l);
for m=l+1:5
b(2)=m2(m);
for n=m+1:6
b(3)=m2(n);
c=m2;
c(n)=[];
c(m)=[];
c(l)=[];
if sum(a)==2*sum(b)
disp(a)
disp(b)
disp(c)
disp(sum(c))
end
end
end
end
end
end
end
Result:
16 46 22
19 10 13
154 101 17
272
Edited on November 9, 2020, 10:47 am
|
Posted by Charlie
on 2020-11-09 10:45:38 |