| Author |
Comment/Response |
Bill Simpson
|
01/24/13 10:41pm
In Response To 'Re: Re: Colored checkerboard' --------- I apologize for my error. There is some copy and paste error that rarely happens when I try to format notebook contents and I have not been able to find exactly what I am doing wrong.
In[1]:= size=2;count=0;
While[True,t=RandomInteger[3, {2, 2}];
success=True;count++; For[i=1,i≤size,i++,For[j=1,j≤size,j++,If[i>1&&t[[i,j]]==t[[i-1,j]]||
i<size&&t[[i,j]]==t[[i+1,j]]||
j>1&&t[[i,j]]==t[[i,j-1]]||
j<size&&t[[i,j]]==t[[i,j+1]],
success=False]]];
If[success,Break[]]
];
Print["It took ",count," tries to find"];
ArrayPlot[t]
From In[1]:=
It took 1 tries to find
Out[3]= ...PlotRemoved...
In[4]:= size=4;count=0;
While[True,t=RandomInteger[3, {2, 2}];
success=True;count++; For[i=1,i≤size,i++,For[j=1,j≤size,j++,If[i>1&&t[[i,j]]==t[[i-1,j]]||
i<size&&t[[i,j]]==t[[i+1,j]]||
j>1&&t[[i,j]]==t[[i,j-1]]||
j<size&&t[[i,j]]==t[[i,j+1]],
success=False]]];
If[success,Break[]]
];
Print["It took ",count," tries to find"];
ArrayPlot[t]
From In[4]:= It took 745 tries to find
Out[6]= ...PlotRemoved...
Hopefully this time I have made no errors.
The number of tries you will need will vary. I let it run for a while with size=6 but gave up before it found a board.
URL: , |
|