From: Morton Goldberg Date: 2007-09-13T00:05:16+09:00 Subject: Re: Filling individual cells in a grid On Sep 12, 2007, at 4:40 AM, Joop Van den tillaart wrote: > So the code can find al the available cell pairs...that can be useful > for me in a next step I have to take but I still have a question... > > On the second thought you had you did something with delta and > neigbours..that is what I need for now but I can't seem to get it to > work... > > How can I find for example: > > All cells that are in a distance of 1 cell from [1, 1] (or directly > 'touch' this cell) ? > > The result then has to be something like: > > [0,0], [1,0], [2,0], [0,1], [2,1], [0,2], [1,2], [2,2] > > I now your code should be able to do this but I'm not sure how... > (jeezz > i feel so noobish) I am not sure I understand what you are asking. If you want to look in a neighborhood around a cell that is two cells deep, shouldn't the deltas be given by tmp =[] (-2..2).each { |dx| (-2..2).each { |dy| tmp << [dx, dy]} } DELTAS = tmp - [[0, 0]] DELTAS # => [[-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2], [-1, -2], [-1, -1], [-1, 0], [-1, 1], [-1, 2], [0, -2], [0, -1], [0, 1], [0, 2], [1, -2], [1, -1], [1, 0], [1, 1], [1, 2], [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]] I mean, don't want to look left, right, over, and under? Regards, Morton