Seven shirts are arranged side by side in a straight line. The 7 shirts have these colors:
purple, red, blue, yellow, brown, orange, and green, although not necessarily in that order.
The following is known about these seven shirts:
- The two colors that start with "b" are not next to each other.
- The Yellow shirt is not next to the Orange shirt.
- The Red shirt is directly between two of the colors each having the second letter as "r".
- The Blue shirt is next to the Orange shirt.
- The Orange shirt is second to the left.
- Either the red, purple, or both are somewhere to the right of the Brown shirt
- There is precisely 1 shirt between the Green shirt and the Orange shirt.
- The Yellow shirt is next to the Green shirt.
Determine the precise order of these seven shirts from the clues provided in the above-mentioned statements.
clearvars, clc
c={'purple','red','blue','yellow','brown','orange','green'};
colors=perms(c);
for i=1:length(colors)
clist=string(colors(i,:));
for j=1:length(clist)
eval([char(clist(j)) '=' char(string(j)) ';'])
end
if abs(brown-blue)==1
continue
end
if abs(yellow-orange)==1
continue
end
if red==1 || red==7
continue
end
rp1=char(clist(red+1));
rp2=char(clist(red-1));
if rp1(2)~='r' || rp2(2)~='r'
continue
end
if abs(blue-orange)~=1
continue
end
if orange~=2
continue
end
if red<brown && purple<brown
continue
end
if abs(green-orange)~=2
continue
end
if abs(green-yellow)~=1
continue
end
disp(clist)
end
finds
"blue" "orange" "red" "green" "yellow" "brown" "purple"
|
Posted by Charlie
on 2022-05-05 12:17:10 |