From: martindemello@... (Martin DeMello) Date: 2002-10-17T03:04:19+09:00 Subject: Re: Please check my algorithm dblack@candle.superlink.net wrote in message news:... > Well, for what it's worth, here's my 1.7-only version (it uses > #inject). I can't help feeling there's a way to do some kind of > double inject, and avoid using the 't' accumulator... but anyway, here > is its current incarnation: > > t = 0 > ISBN_RE.match(self) && > numbers.inject(0) {|x,y| t += x+y; x+y } && > (t % 11) .zero? > end ISBN_RE.match(self) && ( (numbers.inject([0]){|x,y| x << (x[-1]+y)}.inject(0){|x,y| x+y}) % 11).zero? martin