# Replacing elements in an array?

Discussion in 'Ruby' started by Jen, Mar 17, 2011.

1. ### JenGuest

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:

def find_empty!
#Loop through @offspring and where ever there is "_" put a random
number.
4.times do |i|
if @offspring == 0
then @offspring = 9
end
#For debugging with the test puzzle
puts @offspring.inspect
end

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 being very dumb, but if someone could please point me in the right
direction that would be great.

Note I have tried the same thing but using a for loop instead of the
times method. This gave me the same results.

Jen.

Jen, Mar 17, 2011

2. ### Jesús Gabriel y GalánGuest

On Thu, Mar 17, 2011 at 5:56 PM, Jen <> 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 =3D=3D 0
> =A0 =A0then @offspring =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 =3D=3D 0
ruby-1.8.7-p334 :005?> then @offspring =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.

Jesús Gabriel y Galán, Mar 17, 2011

3. ### JP BillaudGuest

JP Billaud, Mar 17, 2011
4. ### JenGuest

Hi,

I used the following code to initialize the offspring array:

def create_pop
#Define an offspring array that will hold the copies of the @board
array
@offspring = []
4.times{ @offspring << @board.clone }
end

At the moment everything is in one huge class 'class Game', though I
plan to have one class for game setup, and one for the evolutionary
algorithm.

Cheers,
Jen.

On 17/03/11 17:23, JP Billaud wrote:
> Your code should work just fine. How did you initialize the @offspring
> array?
>
> JP
>

Jen, Mar 17, 2011
5. ### JenGuest

Hello,

When I run
puts @offspring.inspect

After populating it with copies of @board, but before attempting to
replace the elements containing "_" the result is:

[[[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7, 6, 3,
2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8, 5,
6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8,
2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]], [[0, 4, 5, 9, 8, 7, 6,
2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2,
9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1,
9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6,
4, 1, 7, 8, 2, 3, 5]], [[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4,
3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4,
3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9,
7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]],
[[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7, 6, 3,
2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8, 5,
6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8,
2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]]]

Let me know if you want me to send the rest of my code.

Jen.

On 17/03/11 17:03, Jesús Gabriel y Galán wrote:
> On Thu, Mar 17, 2011 at 5:56 PM, Jen<> 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:
>>
>> def find_empty!
>> #Loop through @offspring and where ever there is "_" put a random number.
>> 4.times do |i|
>> if @offspring == 0
>> then @offspring = 9
>> end
>> #For debugging with the test puzzle
>> puts @offspring.inspect
>> end
>>
>> 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 being
>> very dumb, but if someone could please point me in the right direction that
>> would be great.
>>
>> Note I have tried the same thing but using a for loop instead of the .times
>> 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 == 0
> ruby-1.8.7-p334 :005?> then @offspring = 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
> => nil
> ruby-1.8.7-p334 :011> @offspring = [0,0,0,0]
> => [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]
> => 4
> ruby-1.8.7-p334 :013> @offspring
> => [9, 9, 9, 9]
>
> Can you add the inspecting puts at the beginning of the method and
> show us the result?
>
> Jesus.
>

Jen, Mar 17, 2011
6. ### Gunther DiemantGuest

So a board is an array of arrays and offspring holds three boards.

So @offspring =3D [[row1],...,[row9]]. Waht you wanna check then is
@offspring[j][k] =3D=3D 0
i is the board copy (from 0 to 3 in your code)
j is the row index (from 0 to 8)
k is the column index ( from 0 .. 8)

What you probably wanna do is
@offspring.each do |board_copy|
board_copy.each |row|
(0..8).each { |column| if row[column] =3D=3D 0 then row[column] =3D=3D =
9 }
end
end

2011/3/17 Jen <>

> Hello,
>
> When I run
> puts @offspring.inspect
>
> After populating it with copies of @board, but before attempting to repla=

ce
> the elements containing "_" the result is:
>
> [[[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7, 6, 3, =

2,
> 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6=

,
> 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, =

9,
> 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]], [[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9,=

2,
> 6, 5, 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, =

3],
> [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6,=

9,
> 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]], [[0,=

4,
> 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, =

4,
> 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5=

,
> 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4],
> [9, 6, 4, 1, 7, 8, 2, 3, 5]], [[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, =

5,
> 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4=

,
> 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, =

7,
> 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]]]
>
> Let me know if you want me to send the rest of my code.
>
> Jen.
>
>
> On 17/03/11 17:03, Jes=FAs Gabriel y Gal=E1n wrote:
>
>> On Thu, Mar 17, 2011 at 5:56 PM, Jen<> 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 than=

ks
>>> very much for that!
>>>
>>> So, I now have an @offspring array that takes copies of @board (a sudok=

u
>>> board) according to a population specified by the user.
>>>
>>> The aim is to populate all empty cells in @offspring with random number=

s,
>>> 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:
>>>
>>> def find_empty!
>>> #Loop through @offspring and where ever there is "_" put a random
>>> number.
>>> 4.times do |i|
>>> if @offspring =3D=3D 0
>>> then @offspring =3D 9
>>> end
>>> #For debugging with the test puzzle
>>> puts @offspring.inspect
>>> end
>>>
>>> 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
>>> being
>>> very dumb, but if someone could please point me in the right direction
>>> that
>>> would be great.
>>>
>>> Note I have tried the same thing but using a for loop instead of the
>>> .times
>>> 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 =3D=3D 0
>> ruby-1.8.7-p334 :005?> then @offspring =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.
>>
>>

>
>
>

Gunther Diemant, Mar 17, 2011
7. ### Jesús Gabriel y GalánGuest

On Thu, Mar 17, 2011 at 10:45 PM, Jen <> wrote:
> Hello,
>
> When I run
> =A0puts @offspring.inspect
>
> After populating it with copies of @board, but before attempting to repla=

ce
> the elements containing "_" the result is:
>
> [

[[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7, 6, 3,=
2,
> 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6=

,
> 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, =

9,
> 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]],

[[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7,
6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3],
> [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6,=

9,
> 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]],

[[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7,
6, 3, 2, 1, 5, 4,
> 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5=

,
> 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4],
> [9, 6, 4, 1, 7, 8, 2, 3, 5]],

[[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5,
> 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4=

,
> 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, =

7,
> 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]]

]
>
> Let me know if you want me to send the rest of my code.

This is the problem. The code you showed initially was expecting a
"one-dimension" array, a flattened array,
while here you have an array that contains 4 arrays that contain 9
arrays of integers. To replace all 0s with 9s in this structure you
have to go deeper:

irb(main):001:0> @offspring =3D [[[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2,
6, 5, 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4,
7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2,
5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7,
8, 2, 3, 5]], [[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8,
7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4, 3,
1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9,
7, 1, 8], [7, 1, 8, 2, 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 3, 5]], [[0, 4, 5, 9, 8, 7, 6, 2,
1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2,
9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3,
1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4],
[9, 6, 4, 1, 7, 8, 2, 3, 5]], [[0, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2,
6, 5, 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4,
7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2,
5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7,
8, 2, 3, 5]]]
irb(main):002:0> def find_empty!
irb(main):003:1> @offspring.each do |board|
irb(main):004:2* board.each do |row|
irb(main):005:3* row.map! {|x| x =3D=3D 0 ? 9 : x}
irb(main):006:3> end
irb(main):007:2> end
irb(main):008:1> end
=3D> nil
irb(main):009:0> find_empty!
=3D> [[[9, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7,
6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2,
8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8],
[7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]], [[9, 4, 5,
9, 8, 7, 6, 2, 1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5,
4, 9], [5, 2, 9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8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, 3, 1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3,
5, 9, 6, 4], [9, 6, 4, 1, 7, 8, 2, 3, 5]], [[9, 4, 5, 9, 8, 7, 6, 2,
1], [1, 9, 2, 6, 5, 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2,
9, 8, 1, 6, 4, 7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3,
1, 9, 2], [2, 5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4],
[9, 6, 4, 1, 7, 8, 2, 3, 5]], [[9, 4, 5, 9, 8, 7, 6, 2, 1], [1, 9, 2,
6, 5, 4, 3, 8, 7], [8, 7, 6, 3, 2, 1, 5, 4, 9], [5, 2, 9, 8, 1, 6, 4,
7, 3], [4, 3, 1, 7, 9, 2, 8, 5, 6], [6, 8, 7, 5, 4, 3, 1, 9, 2], [2,
5, 3, 4, 6, 9, 7, 1, 8], [7, 1, 8, 2, 3, 5, 9, 6, 4], [9, 6, 4, 1, 7,
8, 2, 3, 5]]]

Jesus.

Jesús Gabriel y Galán, Mar 17, 2011
8. ### JenGuest

Thanks to everyone who posted for the advice.
I'll test the solutions out ASAP.

Thanks again,
Jen.

Jen, Mar 18, 2011