From: "Kroeger, Simon (ext)" Date: 2006-08-16T18:27:18+09:00 Subject: Re: [QUIZ] Newbie doubts about the quiz > From: Daniel Martin [mailto:martin@snowplow.org] > Sent: Wednesday, August 16, 2006 4:21 AM > > "Marcelo Alvim" writes: > > > 4) You guys could teach me a super-cool Ruby-esque way to > do that that > > I can't even think about right now. > > Note that what I did to solve this was at each step to copy the cells > in the neighborhood of the current cell to a 13 by 13 array so that > the current cell is the middle. This then frees me from thinking > about wraparound or bounds checking while computing which move to make > next. > > Of course, this is only possible if you have a fast way to copy a > rectangular chunk of one two-dimensional array to another. Since I > was using NArray, I had that. You know I like NArray, but perhaps there is an even cooler way this time :) ----------------------------------------------- my_array = [1, 2, 3] another_one = [1, 2, 3] p my_array[-1] #=> 3 grmpf... p another_one[-1] #=> 3 yeah, what else? class << my_array def [] index return nil if index < 0 super end end p my_array[-1] #=> nil, hehe, nice! p another_one[-1] #=> 3 woot, woot ----------------------------------------------- I don't know if this is really the right way, but the OP was asking for a super-cool Ruby-esque way, right? cheers Simon