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

Replies are listed 'Best First'.
Re: Intriguing problem; maybe golf?
by wog (Curate) on May 31, 2001 at 05:52 UTC
    Here is a solution: ( 14 chars between {}s ).

    sub c {(8**$_[0]-1)/7}

    Proof: For any x and n, by factoring, x**(n)-1 == (x-1)(x**(n-1)+x**(n-2)+...+1). So: x**(n-1)+x**(n-2)+...+1==(x**(n)-1)/(x-1). So, for x == 8: 8**(n-1)+8**(n-2)+...+1==(8**(n)-1)/7. And there, the left side is the sequence, the right side my solution.

      Very good ! ++ this ! I like your demonstration.
      It seems that Mathematics are very useful for Golf contest :)

      BobiOne KenoBi ;)

Re: Intriguing problem; maybe golf?
by Masem (Monsignor) on May 31, 2001 at 04:09 UTC
    A recursive solution:
    sub c { my$a=pop;$a==1?1:8**($a-1)+c($a-1) }
    And a non-recursive one:
    sub c { my$a=1;$a+=8**$_ for(1..pop-1);$a }
    updates on that last bit of code
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain