From: Elliot Temple Date: 2006-08-16T05:53:49+09:00 Subject: Re: [QUIZ] Newbie doubts about the quiz On Aug 15, 2006, at 1:49 PM, Marcelo Alvim wrote: > Hey, People. > > I'm a newbie, as the subject implies, and some questions about Ruby > raised when I was trying to solve this quiz. > > I'm not trying to create a very fast solution, I'm only trying to > learn mor of the language. So I'm trying a simple depth-first search > approach. > > I'm going to have this two-dimensional array representing the board. > At each place of the board, I'll probably put the number that is > currently on that place. > > The problem, now, is that I chose not to assume the board as a torus, > but as a flat square. So, I'm doing that simple math going from one > square to the next: if it's an horizontal move, I add 3 or -3 to X; > if it's vertical, apply the same to Y; if it's the diagonal, add 2 or > -2 to both of them. Well, you already know that. Unfortunately, Ruby's > behavior of wrapping arrays over using their negative indices, which I > like very much on most cases, is kind of annoying now, since I want to > invalidate access to negative indices. one way to do it is take the current position and add/subtract the changes, and save that in a variable. don't do an array access yet. now you can use some if statements to check the values are OK before continuing. that's what i did. -- Elliot Temple http://www.curi.us/blog/