o Bruce, Caitlin, Felicia, and Harold went to a bar to have ice cream sundaes.
o Each of them ordered precisely two flavors from amongst the following: chocolate, vanilla, raspberry, and strawberry.
It is known that:
- Bruce did NOT have chocolate.
- Caitlin did NOT have vanilla.
- Felicia did NOT have raspberry.
- Caitlin and Felicia did NOT have any flavors in common.
- Two of them had strawberry.
- Two of them had chocolate.
- Three of them ordered vanilla.
- Harold did NOT have strawberry
- Caitlin had strawberry.
From the above-mentioned clues, determine the two ice-cream flavors ordered by each of the four individuals.
Item 8 was not needed, nor used in the program:
clearvars,clc
bruce=1; caitlin=2; felicia=3; harold=4;
name=["bruce";"caitlin";"felicia";"harold"];
combo=nchoosek('cvrs',2);
n=size(combo,1);
for a=1:n
ch(bruce,:)=combo(a,:);
for b=1:n
ch(caitlin,:)=combo(b,:);
for c=1:n
ch(felicia,:)=combo(c,:);
for d=1:n
ch(harold,:)=combo(d,:);
if ~ismember('c',ch(bruce,:)) && ~ismember('v',ch(caitlin,:)) && ~ismember('r',ch(felicia,:))
if length(intersect(ch(caitlin,:),ch(felicia,:)))==0
if length(strfind([ch(caitlin,:),ch(bruce,:),ch(harold,:),ch(felicia,:)],'s'))==2
if length(strfind([ch(caitlin,:),ch(bruce,:),ch(harold,:),ch(felicia,:)],'c'))==2
if length(strfind([ch(caitlin,:),ch(bruce,:),ch(harold,:),ch(felicia,:)],'v'))==3
if ismember('s',ch(caitlin,:))
for i=bruce:harold
fprintf('%-7s %2s\n',name(i), ch(i,:))
end
end
end
end
end
end
end
end
end
end
end
Results showing initials of the flavors had by each:
bruce vs
caitlin rs
felicia cv
harold cv
|
Posted by Charlie
on 2022-12-11 11:19:00 |