```On Thu, Mar 17, 2011 at 5:56 PM, Jen <jen.bottom / gmail.com> wrote:
> Hello,
>
> This question is following on from my post 'making an array of arrays?', =
but
> as it is about replacing elements I have started a new thread.
>
> The reply to my last arrays related post did solve one problem, so thanks
> very much for that!
>
> So, I now have an @offspring array that takes copies of @board (a sudoku
> board) according to a population specified by the user.
>
> The aim is to populate all empty cells in @offspring with random numbers,
> but for now I am just populating them with '9'.
> Empty cells were represented by '")', but are now represented by '0'
> Currently the population is fixed at 4, and my current code is:
>
> =A0 =A0def find_empty!
> =A0 =A0#Loop through @offspring and where ever there is "_" put a random =
number.
> =A0 =A04.times do |i|
> =A0 =A0if @offspring[i] =3D=3D 0
> =A0 =A0then @offspring[i] =3D 9
> =A0 =A0end
> =A0 =A0#For debugging with the test puzzle
> =A0 =A0puts @offspring.inspect
> =A0 =A0end
>
> When I print out offspring I expect the first element to be changed to 9,=
as
> it was originally set to 0, this is however not the case. I'm sure I'm be=
ing
> very dumb, but if someone could please point me in the right direction th=
at
> would be great.
>
> Note I have tried the same thing but using a for loop instead of the .tim=
es
> method. This gave me the same results.

Your method works, so maybe @offspring doesn't contain what you think.

ruby-1.8.7-p334 :001 > def find_empty!
ruby-1.8.7-p334 :002?>      #Loop through @offspring and where ever
there is "_" put a random number.
ruby-1.8.7-p334 :003 >        4.times do |i|
ruby-1.8.7-p334 :004 >          if @offspring[i] =3D=3D 0
ruby-1.8.7-p334 :005?>          then @offspring[i] =3D 9
ruby-1.8.7-p334 :006?>          end
ruby-1.8.7-p334 :007?>        #For debugging with the test puzzle
ruby-1.8.7-p334 :008 >          puts @offspring.inspect
ruby-1.8.7-p334 :009?>        end
ruby-1.8.7-p334 :010?>   end
=3D> nil
ruby-1.8.7-p334 :011 > @offspring =3D [0,0,0,0]
=3D> [0, 0, 0, 0]
ruby-1.8.7-p334 :012 > find_empty!
[9, 0, 0, 0]
[9, 9, 0, 0]
[9, 9, 9, 0]
[9, 9, 9, 9]
=3D> 4
ruby-1.8.7-p334 :013 > @offspring
=3D> [9, 9, 9, 9]

Can you add the inspecting puts at the beginning of the method and
show us the result?

Jesus.

```