From: dblack@... Date: 2002-10-17T23:16:55+09:00 Subject: Re: Please check my algorithm Hello -- On Thu, 17 Oct 2002, Michael Campbell wrote: > > --- Martin DeMello wrote: > > "Mike Campbell" wrote in message > > news:... > > > > > > > > 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... > > > > Nope, just to use two injects rather than an accumulator (which was > > what was asked). Which needed the first inject to collect into an > > array (since the second inject needed to be passed one). > > > > Besides which, golfing and playing variations on a theme are fun, > > as > > long as you don't mistake the result for maintainable code :) > > > Yeah, I apologize for my tone there; I didn't mean to come across as > nasty as it sounded. OK, then I apologize for the somewhat icy post that just crossed in the mail with yours :-) > It amuses me sometimes to see the accolades for how much easier ruby > is to read/write (or how much harder perl is!) because of the more > regular syntax. Then inevitably when someone asks how to do > something, the responses leapfrog each other in terseness _well_ > beyond reasonable readability. =) I was actually thinking of turning that #inject one into a golf challenge.... :-) which I enjoy doing, for the mental exercise, and the insights into Ruby that always seems to crop up, though the results are generally not very pleasing code. It seems to me that there are two distinct forms of code-shortening in Ruby: first, the golf/possibly-obfuscated type, and second, the thing where you work on a program in Ruby and as you work, it gets shorter *and* clearer. I enjoy the first, but I love the second :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav