Of course, that's just an example(off the top of my head, as it were). I want to see if anyone can figure out a shorter way to do this. I came up with a regular expression that does it in 27 characters...there aren't any rules I want to set really, except that I'd rather not see recursion(but that would be a longer technique anyway, I imagine). I'll post my solution after a while...sub calculate { return 1 if $_[0]==1; return (8**($_[0]-1) + calculate($_[0]-1)) }
actually, it's probably less than 27 characters, that's just the count on the raw regex; i.e., I haven't tried to shorten it as per 'perl golf'(and to make some humor, i used in the s/// operator the /geese option :)
Golf away.
Edited 2001-05-30 by Ovid
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Intriguing problem; maybe golf?
by wog (Curate) on May 31, 2001 at 05:52 UTC | |
by bobione (Pilgrim) on May 31, 2001 at 13:26 UTC | |
|
Re: Intriguing problem; maybe golf?
by Masem (Monsignor) on May 31, 2001 at 04:09 UTC |