Imagine, if you will, a number sequence(fibonacci numbers may help you get an understanding of where I'm coming from). This sequence starts with 1. 1 equals 1; 2 equals 9; 3 equals 73; etc. To get the i-th number, you must use this equation --8^i-1 + (the i-th-1 number in the sequence). In perl, you could say:
sub calculate { return 1 if $_[0]==1;
return (8**($_[0]-1) +
calculate($_[0]-1))
}
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...
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.