in reply to Re: Is Perl less compact than Ruby? (Kind of competition)
in thread Is Perl less compact than Ruby? (Kind of competition)

Another update, bringing to 331. Though I'm not sure the change is legal, it runs the Tic-Tac-Toe program.
map{push@L,push@C,lc=~/./g}<>;sub p{$_=pop@n}sub w{push@n,@_}while($n< +@C){$_=$C[$n++];if(/h/){p;w$n[-1-abs];$_>0&&splice@n,-2-$_,1}if(/n/){ +w 0;$b<0||w$b+7*p while($b=index"htaoinse",$C[$n++])<7}$0=p,p,w int$_ +/$0,$_%$0if/e/;$a=p,p&&($a?$n=$L[$a-2]:last)if/t/;/a/?w 2+grep$n>$_,@ +L:/o/?print chr p:/s/?w-(p)+p:/i/&&w+($_=getc)?ord:-1}
The change was to functionally remove the 0 at the beginning of @L. Adjusting the subscripts used to access @L seems to result in an acceptable performance.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: 29 characters to beat Ruby ...
by Matts (Deacon) on Feb 20, 2002 at 09:55 UTC
    One thing people often forget is that push@L,values is a semantically equivalent (modulo being faster) to @L=@L,values - a saving of one character per push, or three characters in the above, bringing you down to 328.
      I tried @L=@L,push@C,lc=~/./g and it didn't work. I don't know enough of the language to be able to say why, but it didn't.

      This could only apply to the first push because I need the return value of the second push to be the value of the @L. Remember, @L is recording the byte that starts each line. @C is the list of bytes.

      In addition, map{push@L,push@C,lc=~/./g}for 0,<>; also didn't work. It puts 1 as the first element of @L, and 0 as the first element of @C. *shrugs*

      However, we can add a character, going back up to 327, and get it right:

      @L=(0,map{push@C,lc=~/./g}<>}; ---- Results in ---- @L=(0,map{push@C,lc=~/./g}<>};sub p{$_=pop@n}sub w{push@n,@_}while($n< +@C){$_=$C[$n++];if(/h/){p;w$n[-1-abs];$_>0&&splice@n,-2-$_,1}if(/n/){ +w 0;$b<0||w$b+7*p while($b=index"htaoinse",$C[$n++])<7}$0=p,p,w int$_ +/$0,$_%$0if/e/;$a=p,p&&($a?$n=$L[$a-1]:last)if/t/;/a/?w 1+grep$n>$_,@ +L:/o/?print chr p:/s/?w-(p)+p:/i/&&w ord getc||-1}

      Update: Make that 326 again.

      @L=(0,map{push@C,lc=~/./g}<>};sub p{$_=pop@n}sub w{push@n,@_}while($n< +@C){$_=$C[$n++];r,w($n[-1-abs]),$_>0&&splice@n,-2-$_,1if/h/;if(/n/){w + 0;$b<0||w$b+7*p while($b=index"htaoinse",$C[$n++])<7}$0=p,p,w int$_/ +$0,$_%$0if/e/;$a=p,p&&($a?$n=$L[$a-1]:last)if/t/;/a/?w 1+grep$n>$_,@L +:/o/?print chr p:/s/?w-(p)+p:/i/&&w ord getc||-1}

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Received! Only two bytes because first push now counts number of elements in @C not pushes elements itself.

      @a1=@a2,@a3 doesn't work :( parentheses needed

increasing on 2 bytes
by locked_user mtve (Deacon) on Feb 20, 2002 at 10:02 UTC

    Excellent tweak with push!

    map{push@L,push@C,lc=~/./g}0,<>; should fix this. It's nice question but I believe impossibility to jump on first line is some violation of language. It's my fault of incorrect target setting.