Four girls, Willow, Ximena, Yvonne, and Zelda, are standing in a line. Exactly one girl plays baseball and soccer but not basketball.
The following facts are known:
- Two girls who do NOT play baseball are standing next to Willow.
- Ximena is the only girl standing next to exactly one soccer player.
- Yvonne is the only girl NOT standing next to exactly one basketball player.
Who plays baseball and soccer, but not basketball?
clc
lines=perms('wxyz');
base=4; soc=2; basket=1;
for i=1:length(lines)
line=lines(i,:);
if all(line([1 4])~='w')
w=strfind(line,'w');
x=strfind(line,'x');
y=strfind(line,'y');
for a=0:7
g(1)=a;
for b=0:7
g(2)=b;
for c=0:7
g(3)=c;
for d=0:7
g(4)=d;
srch=base+soc;
ix=find(g==srch);
if length(ix)==1
if ~any(bitand(g([w-1 w+1]),base))
nxtto=zeros(1,6);
for j=1:4
if bitand(g(j),soc)
nxtto([j j+2])=nxtto([j j+2])+1;
end
end
nxtto=nxtto(2:5);
f=find(nxtto==1);
if length(f)==1
if line(f)=='x'
nxtto=zeros(1,6);
for j=1:4
if bitand(g(j),basket)
nxtto([j j+2])=nxtto([j j+2])+1;
end
end
nxtto=nxtto(2:5);
f=find(nxtto==1);
if length(f)==3
if line(10-sum(f))=='y'
disp(line)
disp(char(g+48))
disp(' ')
end
end
end
end
end
end
end
end
end
end
end
end
finds these 8 scenarios that fit:
zwxy
1106
zwxy
1506
yzwx
6031
yzwx
6071
yxwz
6011
yxwz
6051
xwzy
1306
xwzy
1706
The first line of each lists the order of the girls, by initial.
The second line in each case shows below each girl's initial, a number whose bits represent baseball (value 4), soccer (value 2) and basketball (1). In each case, Yvonne has a 6 (i.e. 4+2) below her initial, indicating she plays baseball and soccer but not basketball. No other girl has a 6 under her initial.
|
Posted by Charlie
on 2022-11-11 10:26:34 |