Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Colored checkerboard' topicStudent Support Forum > General > Archives > "Colored checkerboard"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
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: ,

Subject (listing for 'Colored checkerboard')
Author Date Posted
Colored checkerboard Savage 01/22/13 11:21am
Re: Colored checkerboard Bill Simpson 01/22/13 10:30pm
Re: Re: Colored checkerboard Savage 01/24/13 1:41pm
Re: Re: Re: Colored checkerboard Bill Simpson 01/24/13 10:41pm
Re: Colored checkerboard yehuda 01/23/13 06:46am
Re: Colored checkerboard Bill Simpson 01/25/13 3:25pm
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic