In creating Saturn, I started with the program I wanted, then golfed it enough to fit into the required shape.

I'd like to reduce it further and thought it might make an interesting golf. There is a precedent for this: in 1971, Alan Shepard thought the moon might make an interesting golf.

OK, so it's probably not the most interesting of golfs and is certainly longer than most. Yet if it can be significantly shortened, that leaves more space to add more visual effects and so improve the Saturn obfu. I've no idea what new effects to add yet, so if you've got some cool ideas on that score, I'd love to hear about them.

I've prepared a standalone program below that weighs in at a whopping 491 strokes (excluding newlines). Update: Score is for code before __DATA__ only, you get the shape for free in this game. (To make testing less tedious, I've shortened the delays between shapes). It's recommended it be run in a console window at least 90 chars wide by 46 deep.

This program is way too fat. Can you help it lose some weight?

sub I{s-^-$"x$_[1]-gem;$/x$_[0].$_.$/} sub D{$~=pop;system($^O=~Win?CLS:"clear"),print, select$Z,$Z,$Z,$~for@_} sub R{$i=0;join$/,map{$j=0;join"",grep!($j++%$_[0]),/./g} grep!($i++%$_[0]),@S} $S=$_=do{local$/;<DATA>}; y---c>$-and$-=y---cfor@S=/.+/g;$_.=$"x-(y---c-$-)for@S; D(@X=(I(20,41,$_="."),I(20,41,$_=O),I(15,31,$_=R 4), I(13,28,$_=R 3),I(10,20,$_=R 2),$S),.3); D((map{$n=$_;join($/,map($_ x$n,R($_)=~/.+/g),"")x$_}2..4) [0..2,1,0],.2); D$S,join("",map(reverse.$/,@S)),.1for$%..5;D reverse(@X),.3 __DATA__ + '''''' + ''''''''''' ''' +'''''''''''' '''''' +''''''''''' ''''''''' +'''''''''' ''''''''''' +''''''''' ''''''''''''' +'''''''' ~~~~~~~~~~~~~ ''''''' '' +''''''' ~~~~~~~~~~~~~~~~~~~ '''' '' +'''''' ~~~~~~~~~~~~~~~~~~~~~~~~ ''' +'''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '''' +''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ''''' +' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '''''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ''''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ''''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ''' ~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ''' ~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ''' ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ''' ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ''' ~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ ''' ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ ''' ~~~~~~~~~~~~~ ''~~~~~~~~~~~~~~~~~~~ ''' ~~~~~~~~~~~~~~~ '''''~~~~~~~~~~~~~~~~ ''' ~~~~~~~~~~~~~~~~ '''''' ~~~~~~~~~~~~~ ''' ~~~~~~~~~~~~~~~~~ ''''' ~~~~~~~~~~ ''' ~~~~~~~~~~~~~~~~~~ '''''' ~~~~~~ ''' ~~~~~~~~~~~~~~~~~~~~ ''''''' ~~ ''' ~~~~~~~~~~~~~~~~~~~~~ ''''''' '''' ~~~~~~~~~~~~~~~~~~~~~ ''''''''' ''''' ~~~~~~~~~~~~~~~~~~~~~~ '''''''''' ''''''''' ~~~~~~~~~~~~~~~~~ '''''''''''''''''''''' ~~~~~~~~~~ '''''''''''''''''''' '''''''''''''''''' '''''''''''''''' '''''''''''''' ''''''''''' ''''''

Replies are listed 'Best First'.
Re: Playing Golf on Saturn
by DrHyde (Prior) on Oct 15, 2004 at 09:01 UTC
    There's one hell of a lot of redundancy in the data, which is part of the program. Compress it. Even trivial encoding like RLE reduces it from 2451 characters to 525 characters. The encoding here is simply a character followed by digits for the number of times it appears.
    75'6 1 71'11 1 67'15 1 64'17 1 61'19 1 59'20 1 57'21 1 37~13 5'7 6'9 1 34~19 3'4 8'8 1 31~24 12'7 1 28~29 9'7 1 26~32 7'6 1 25~34 5'6 1 24~36 3'5 1 23~38 1'5 1 22~37 2'4 1 21~36 2'4 1 21~35 2'3 1 20~34 2'3 2~2 1 20~32 2'3 2~4 1 20~30 2'3 2~6 1 20~28 2'3 2~8 1 20~26 2'3 2~10 1 20~24 2'3 2~11 1 20~22 2'3 2~13 1 18'2~19 2'3 2~15 1 16'5~16 2'3 2~16 1 14'6 2~13 2'3 2~17 1 13'5 5~10 2'3 2~18 1 11'6 7~6 2'3 2~20 1 9'7 10~2 2'3 2~21 1 8'7 12'4 2~21 1 6'9 8'5 2~22 1 5'10 4'9 4~17 1 4'22 9~10 1 3'20 1 2'18 1 1'16 1'14 1'11 1 2'6
    This can be trivially improved by:
    • Optimising single characters to have no trailing number;
    • encoding numbers into single characters.
    That latter is moderately interesting. After getting rid of 1s, we have to encode numbers in the range 2 to 71, and you have four unique characters in your data. So we need 74 unique characters. Represent your four data characters by the first four normally printable ASCII characters - \t, \n, space and pling. Then represent the numbers 2 to 71 with ASCII characters 34 to 103.

      Finding the best compression for this data is certainly an interesting problem and I don't mind at all if people pipe up on that (I used a compression scheme in Spinning World, for example, and am always looking for improvements).

      However, for the purposes of this golf game, let me clarify that the golf score (491 in my example fat test program above) is calculated for the code before the __DATA__ only. You get the __DATA__ and the Saturn shape for free in this game because in the obfu I can, cough, get it very cheaply by reading the source.

Re: Playing Golf on Saturn (437)
by eyepopslikeamosquito (Archbishop) on Oct 17, 2004 at 02:06 UTC

    D'oh, don't need to calculate the maximum line length (in $-) since it's known to be 82 for shape Saturn. That, plus some routine whittling has reduced the golf score by 39 strokes down to 452.

    sub I{s-^-$"x$_[1]-gem;$/x$_[0].$_.$/} sub D{$~=shift;system($^O=~Win?CLS:"clear"),print, select$Z,$Z,$Z,$~for@_} sub R{$i=0;join$/,map{$j=0;join"",grep!($j++%$_[0]),/./g} grep!($i++%$_[0]),@:} $S=join"",@:=<DATA>;chop@:; $_.=$"x-(y---c-82)for@:; D.3,@X=(I(20,41,$_="."),I(20,41,$_=O),I(15,31,$_=R 4), I(13,28,$_=R 3),I(10,20,$_=R 2),$S); D.2,(map{$n=$_;join($/,map$_ x$n,R($_)=~/.+/g,"")x$_}2..4) [0..2,1,0]; D.1,$S,join"",map+reverse.$/,@:for$%..5;D.3,reverse@X

    Update: Down to 437 now. There must be more there, let's see if thospel or mtve can beat this by 100 strokes. :-)

    sub I{$x=pop;$x=~s-^-$"x$_[1]-gem;$/x$_[0].$x.$/} sub D{$~=shift;system($^O=~Win?CLS:"clear"),print, select$Z,$Z,$Z,$~for@_} sub R{$i=0;join$/,map{$j=0;join"",grep!($j++%$_[0]),/./g} grep!($i++%$_[0]),@:} $S=join"",@:=<DATA>; chop,$_.=$"x-(y---c-82)for@:; D.3,@X=(map(I(20,41,$_),".",O),I(15,31,R 4), I(13,28,R 3),I(10,20,R 2),$S); D.2,map{$n=$_;join($/,map$_ x$n,R($_)=~/.+/g,"")x$_}2..4,3,2; D.1,$S,join"",map+reverse.$/,@:for$%..5;D.3,reverse@X

    Still chipping away... 425

    sub I{$x=pop;$x=~s-^-$"x$_[1]-gem;$/x$_[0].$x.$/} sub D{system$^O=~Win?CLS:"clear";print;select$Z,$Z,$Z,pop} sub R{$i=0;join$/,map{$j=0;join"",grep!($j++%$_[0]),/./g} grep!($i++%$_[0]),@:} $S=join"",@:=<DATA>; chop,$_.=$"x-(y---c-82)for@:; D.3for@X=(map(I(20,41,$_),".",O),I(15,31,R 4), I(13,28,R 3),I(10,20,R 2),$S); for$n(2..4,3,2){$_=join($/,map$_ x$n,R($n)=~/.+/g,"")x$n;D.2} D.1for($S,join"",map+reverse.$/,@:)x6; D.3for+reverse@X