- #1

bor0000

- 50

- 0

%4wifes problem: man and wife sit at the corners of the table. others may sit so that no man sits next to his wife or another man

%how many possible arrangements?

function c = fourcouples(trials)

pos=[1,0,0,0,0,0,0,0,0,1];

x=[];

c=0;

count=1;

counter=0;

while count[ trials %set matrix x with all possible combinations

for i=2:9

pos(i)=rand;

if pos(i)[ =.25

pos(i)=1;

else if pos(i)[ =.50

pos(i)=2;

else if pos(i)[ =.75

pos(i)=3;

else

pos(i)=4;

end %of if

end %set random variables, end of forloop1

k=0;

for j=2:8

if pos(j)~=pos(j+1)

k=k+1;

end %end of if

end %end for loop2

if k==7

x=[x;pos]; %augment x by a new arrangement

counter=counter+1; %number of rows of rows of x

end %of if

count=count+1;

end %of while loop

i=1;

y=[];

while i[ =counter %get rid of dupblicate arrangements by setting new matrix y

z=y;

y=[y;x(i,:)];

if det(y)==0

y=z;

else

c=c+1;

end

i=i+1;

end

end

return