Hexadecimal representation of pi
weixi
created: 2006-03-07 07:07:06
This is actually the outcome of a game of perl golf. The task was to print a hexadecimal representation of pi, where the digits are not calculated en bloc but one after the other. The longer the program runs the more digits it produces.

However, the algorithm itself is rather obfuscated already and reducing the number of characters for the perl golf resulted in another level of obfuscation. So I thought the obfuscation section would be the right place for it to post anyway.


        $|=print 3.2;sub O{8*($@-$_)+(1,4,5,6)[$:]};sub 
       o{(-4,2,1,1)[$:]/O};while($,=++$@){for$:(0..3){
      for         (0..$@)             {for$"
                  (($/=1)             ..$_){
                 ($/*=16)             %=O};
                 $,-=$/                *o}$,
                 -=16**                 $_*o
               for-6..-                   1}printf
             "%x",$,*                   16%16}
Re: Hexadecimal representation of pi
created: 2006-03-07 08:53:16

As you're golfing, there are a few trivial modifications that can save a few characters. Omit the semicolons after the sub definitions and for loops, and change ($/*=16)%=O to $/=$/*16%O.


        $|=print 3.2;sub O{8*($@-$_)+(1,4,5,6)[$:]}sub 
       o{(-4,2,1,1)[$:]/O}while($,=++$@){for$:(0..3){
      for         (0..$@)             {for$"
                  (($/=1)             ..$_){
                  $/=$/*              16%O}
                 $,-=$/                *o}$,
                 -=16**                 $_*o
               for-6..-                   1}printf
             "%x",$,*                   16%16}

Re^2: Hexadecimal representation of pi
created: 2006-03-07 10:04:15
Thanks for the hints!

Now that you made me aware of the semicolons after the sub definitions, I am really stunned I didn't realize those myself.

Re: Hexadecimal representation of pi
created: 2006-03-09 05:06:24
Right now, pi golf is going on polish site.

perlmonks.org content © perlmonks.org and ambrus, mtve, weixi

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03