in reply to 29 characters to beat Ruby ...
in thread Is Perl less compact than Ruby? (Kind of competition)

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.

Replies are listed 'Best First'.
Re: Re: 29 characters to beat Ruby ...
by dragonchild (Archbishop) on Feb 20, 2002 at 13:19 UTC
    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.

oops
by locked_user mtve (Deacon) on Feb 20, 2002 at 10:46 UTC

    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