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

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.

Replies are listed 'Best First'.
Re: *** japhy's qw is GODLIKE ***
by japhy (Canon) on Feb 20, 2002 at 21:40 UTC
    In light of this newline problem, I offer:
    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;/g;eval

    _____________________________________________________
    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:??;

      And I offer a saving of 1:
      sub p{$_=pop@n}sub w{@n=@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;/g;eval
        Except that = binds tighter than ,, so your code would have to be @n=(@n,@_) instead, which is more characters.

        _____________________________________________________
        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:??;

Re: *** japhy's qw is GODLIKE ***
by japhy (Canon) on Feb 20, 2002 at 21:19 UTC
    I don't get it. Where are the Ln: labels being inserted? At the beginning of each line, right? So then, where are the newlines in $_?

    _____________________________________________________
    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:??;

      At the beginning of each line, right?

      Yes.

      So then, where are the newlines in $_?

      They are remains because of s/^/blahblah/mg

      Structure of ETA source (feeded on input) remains the same, it's only enlarging in width. Clear now? I'm ready to explain more carefully.

        The structure does not remain the same. Any characters out of the ordinary are removed.

        _____________________________________________________
        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:??;