From: William Djaja Tjokroaminata Date: 2002-09-20T05:58:18+09:00 Subject: Re: How to Efficiently Calculate the Pattern of Zeros and Ones? Hi, If the "shifts data through it" is accomplished using Ruby Array#push() and Array#shift(), then probably the code is indeed very easy to write, but probably not very efficient in the background. I like the answer given in the first response, as I think it mimics how regular expression works (using some "states"). Regards, Bill =========================================================================== Joel VanderWerf wrote: > I had to go back and check whether each_with_neighbors generated lots of > arrays or not. It turns out that it doesn't. Instead, it keeps a single > array, shifts data through it, and yields the array. So it should be > fairly efficient as pure ruby code goes. > However, this may surprise users who modify the array in the iterator > block, so I'll slip a warning into the docs. > If your rows are short, each_with_neighbors is not very efficient > because of the "warm up" and "cool down" to deal with the cases near the > edge.