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

Thanks to tadman, cLive ;-) , blakem, dragonchild, grinder, Matts, jynx and PerlMonks.org, Perl version in now
officially 333 bytes (or 327 bytes with some cheating), while Ruby is still 306 bytes.

map{push@L,push@C,lc=~/./g}0,<>;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+($_ =getc)?ord:-1}

Replies are listed 'Best First'.
Completely different algorithm
by locked_user mtve (Deacon) on Feb 20, 2002 at 15:18 UTC

    Beta version, 325 bytes, expanded view, subject to optimizations:

    sub p{$_=pop@n} sub w{push@n,@_} %D=( H=>'0p;w$n[-1-abs];$_>0&&splice@n,-2-$_,1', T=>'1$t=p;p&&goto"L$t"', A=>'2w$L+1', O=>'3print chr p', I=>'4w+($_=getc)?ord:-1', N=>'5w$N++', S=>'6w-(p)+p', E=>'7$0=p;p;w int$_/$0,$_%$0' ); $/=\-1;$_=uc<>; s#.#$D{$&}=~/(.)(.*)$/&&"\$N?$1>6?\$N=0:w $1+7*p:do{$2};"#eg; s/^/$i++,"L$i:\$L=$i;"/emg; eval; L0:
      Here's some more, then. It also adds the (missing?) newline to the end of each command.
      sub p{$_=pop@n} sub w{push@n,@_} $/=$T;$_=uc<>; s#.#+{qw( H 0p;w$n[-1-abs];$_>0&&splice@n,-2-$_,1 T 1$t=p;p&&goto"L$t" A 2w$L+1 O 3print+chr+p I 4w+($_=getc)?ord:-1 N 5w$N++ S 6w-(p)+p E 7$0=p;p;w+int$_/$0,$_%$0 )}->{$&}=~/./&&"\$N?$&>6?\$N=0:w $&+7*p:do{$'};\n"#eg; s/^/L${\++$i}:\$L=$i;/mg; eval; L0:

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

        Now world record is 290 bytes:

        sub p{$_=pop@n}sub w{push@n,@_}$/=$T;$_=uc<>;s#.#+{qw(E 7$0=p;p;w+int$ +_/$0,$_%$0 H 0p;w$n[-1-abs];$_>0&&splice@n,-2-$_,1 I 4w+($_=getc)?ord:-1 A 2w$L+1 + N 5w$N++ S 6w-(p)+p O 3print+chr(p) T 1$t=p;p&&goto"L$t")}->{$&}=~/./&&"\$N?$&> +6?\$N=0:". "w $&+7*p:do{$'};"#eg;s/^/L${\++$i}:\$L=$i;/mg;eval

        Everything working as expected, no cheating.

        We did it! Perl is winner!

        It also adds the (missing?) newline

        Nope, it was ok. I also fixed warning and unused last label.

        Please note that Tic-Tac-Toe program unrolled to around megabyte of Perl code, so eval takes some time.

      Nicely done! Shave three with I=>'4w 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.