From: "Shot (Piotr Szotkowski)" Date: 2008-12-29T06:27:00+09:00 Subject: Re: New to Ruby: copying arrays? --Sr1nOIr3CvdE5hEN Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable John Park: > Stefano Crocco wrote: >> You can use Marshal.dump and Marshal.load: >> a =3D [["a", "b"],["c", "d"]] >> b =3D Marshal.load(Marshal.dump(a)) >> a[0][0].upcase! >> puts a[0][0] #=3D> A >> puts b[0][0] #=3D> a > Just experimented with it in irb. > Awesome! Exactly what I was hoping for! To extend on the above, what I would do would be to create a separate Board class to represent your Sudoku board, rather than directly using Array for this. First, you can then implement it in various ways, and (as long as you maintain the same methods to access and opearte on it) it would be transparent to the Sudoku solver whether your Board is implemented as an Array of three three-element Arrays, a nine-element =E2=80=98flat=E2= =80=99 Array, or anything else (say, maybe 27 Sets containing 81 elements in non-disjoint groups of nines?). Second, you can then have class Board def dup Marshal.load Marshal.dump(self) end end (which is an idiom I use extensively in my code) and simply use @initialboard =3D @board.dup =E2=80=A6 @board =3D @initialboard.dup in your solver. :) -- Shot --=20 FORTRAN was the language of choice for the same reason that three-legged races are popular. -- Ken Thompson --Sr1nOIr3CvdE5hEN Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFJV/Coi/mCfdEo8UoRAlFaAJ9tnG/pmrwCbPuuRdNkloW6KGZcnQCbB+Q0 bBNI5tqtsaRQUB38AqyUB8s= =aJa6 -----END PGP SIGNATURE----- --Sr1nOIr3CvdE5hEN--