Art, Bob, Cab, and Ida are guards in a museum.
It is known that:
- Each of Art, Bob, and Cab stands guard on exactly four days every week.
- Exactly two persons stand guard together every day.
- No person stands guard three days in a row.
- Here is a partial listing that shows when they stand guard every week:
+-----+-----+-----+
| Sun | Art | Bob |
+-----+-----+-----+
| Mon | Cab | ? |
+-----+-----+-----+
| Tues| Ida | ? |
+-----+-----+-----+
| Wed | Art | ? |
+-----+-----+-----+
|Thurs| Bob | ? |
+-----+-----+-----+
| Fri | Cab | ? |
+-----+-----+-----+
| Sat | Ida | ? |
+-----+-----+-----+
Who does NOT stand guard with Ida?
clearvars, clc
string1='aciabci';
strings='aabbcc';
strings=uniqueperms(strings);
b=length(strings);
b=repmat('b',b,1);
strings=[b strings];
good=false;
i=1;
while i<= length(strings)
x1=strfind(string1,'a');
x2=strfind(strings(i,:),'a');
tst=' ';
tst(union(x1,x2))='a';
aaa=strfind(tst,'aaa');
x1=strfind(string1,'b');
x2=strfind(strings(i,:),'b');
tst=' ';
tst(union(x1,x2))='b';
bbb=strfind(tst,'bbb');
x1=strfind(string1,'c');
x2=strfind(strings(i,:),'c');
tst=' ';
tst(union(x1,x2))='c';
ccc=strfind(tst,'ccc');
if ~isempty(aaa) || ~isempty(bbb) || ~isempty(ccc)
strings(i,:)=[];
i=i-1;
end
i=i+1;
end
i=1;
while i<= size(strings,1)
if sum(string1==strings(i,:))
strings(i,:)=[];
i=i-1;
end
i=i+1;
end
for i=1:size(strings,1)
disp(string1)
disp(strings(i,:))
end
disp(size(strings,1))
Checks for everything but one condition, but gives us a listing for the three remaining possibilities:
aciabci
babcabc
aciabci
bacbcab
aciabci
bbcbcaa
The thing the program neglected to check for was that Friday, Saturday and Sunday are three days in a row (as are Saturday, Sunday and Monday), and the third possibility shown has Art working three days in a row over a weekend.
The first two possibilities remain, and in ehach of them Ida guards only with Bob on one day and Cab on another, never with Art.
|
Posted by Charlie
on 2022-08-28 10:44:44 |