Forum: Ruby Help defining multi-dimensional array

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
victor.reyes (Guest)
on 2005-12-08 21:41
(Received via mailing list)
Ruby Team,
I would like to define a 3x3 array of integers.
Can anyone tell me how this is done?
I would like to start playing with Ruby and I want to start by solving
Magic
Squares.

Thank you

Victor
James G. (Guest)
on 2005-12-08 21:49
(Received via mailing list)
On Dec 8, 2005, at 1:38 PM, Victor R. wrote:

> Ruby Team,
> I would like to define a 3x3 array of integers.
> Can anyone tell me how this is done?

Here's one way:

 >> Array.new(3) { Array.new(3) { 0 } }
=> [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

Hope that helps.

James Edward G. II
dandiebolt (Guest)
on 2005-12-08 23:14
(Received via mailing list)
#Third Order Magic Cube
b={}
b["0,0,0"]=1
b["0,0,1"]=15
b["0,0,2"]=26
b["0,1,0"]=17
b["0,1,1"]=19
b["0,1,2"]=6
b["0,2,0"]=24
b["0,2,1"]=8
b["0,2,2"]=10
b["1,0,0"]=23
b["1,0,1"]=7
b["1,0,2"]=12
b["1,1,0"]=3
b["1,1,1"]=14
b["1,1,2"]=25
b["1,2,0"]=16
b["1,2,1"]=21
b["1,2,2"]=5
b["2,0,0"]=18
b["2,0,1"]=20
b["2,0,2"]=4
b["2,1,0"]=22
b["2,1,1"]=9
b["2,1,2"]=11
b["2,2,0"]=2
b["2,2,1"]=13
b["2,2,2"]=27
ara.t.howard (Guest)
on 2005-12-09 05:49
(Received via mailing list)
On Fri, 9 Dec 2005, Victor R. wrote:

> Ruby Team,
> I would like to define a 3x3 array of integers.
> Can anyone tell me how this is done?
> I would like to start playing with Ruby and I want to start by solving Magic
> Squares.
>
> Thank you
>
> Victor

check out narray - i think the functionality of it will help greatly.

-a
victor.reyes (Guest)
on 2005-12-11 06:55
(Received via mailing list)
Thank you all for your help.
This topic is locked and can not be replied to.