From: dblack@... Date: 2002-10-17T23:09:24+09:00 Subject: Re: Please check my algorithm Hello -- On Thu, 17 Oct 2002, Mike Campbell wrote: > > 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 > > Was the intent here to shorten the code to beyond obfuscation threshholds? > > I thought that was one thing so many on this group rail against perl for... I don't there exists some particular code-length threshhold, to drop beneath which in the course of discussing a particular coding problem signifies a general embrace of code obfuscation. Things can easily become much too Simon-Says-like ("Ah! Caught you eliminating a temporary variable -- you're out!"). It's really more of an on-going process. In this case, actually, since #inject is on its way in >=1.7, I'm inclined to give the code the benefit of the doubt and try to crank up my own ability to grasp #inject usage. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav