Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Is Perl less compact than Ruby? (Kind of competition)

by cLive ;-) (Prior)
on Feb 18, 2002 at 21:12 UTC ( [id://146250]=note: print w/replies, xml ) Need Help??


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

Well, since it doesn't work under strict, you can safely drop:
$n=0;
that's another 5 chars.

Also, put pop@n in a sub at the beginning:

sub p{pop@n}
then replace:
pop@n => p
throughout. another 20 chars saved.
sub w{push@n,$_[0]}sub p{pop@n}map{push@L,@C+0;push@C,split//,lc}<>;wh +ile($n<@C){$_=$C[$n++];if(/n/){$0=0;/-/ or$0=$_+$0*7while($_=index"ht +aoinse",$C[$n++])<7;w$0}if(/t/){$_=p@n;$_?$n=$L[$_-1]:last if p@n}/a/ +&&push@n,1+grep$n>$_,@L;if(/h/){$_=p@n;$n[$#n-abs];$_>0&&splice@n,@n- +2-$_,1}/o/&&print+chr(p@n);/s/&w-(p@n)+p@n;$0=p@n,$_=p@n,w(int$_/$0), +$_%$0if/e/;w($_=getc)?ord:-1if/i/}

cLive ;-)

Update - d'oh, yep, another 16 chars saved by changing p@n to p (updated above) - that means we can also save another 10 chars by whacking push@n,'whatever' into a sub.

What's that now? 379 chars?

--
seek(JOB,$$LA,0);

Replies are listed 'Best First'.
20 bytes from cLive ;-)
by mtve (Deacon) on Feb 18, 2002 at 21:25 UTC

    Excellent!

    pop@n => p@n

    or simply to 'p', yes?

      and another similar optimization on push, now EQUAL TO RUBY - 357 bytes!!!

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

      Thank you!!! What's next?

        Well, actually Ruby is 356 bytes (357 minus one backslash), so applying merlyn's hack on last line:

        ... v+($_=getc)?ord:-1if/i/}

        If you are going to choose where to put your newline then the Ruby is 356:
        n=[];p=$<.readlines;f=l=c=0;loop{p[l].downcase.each_byte{|y|f>0?$6?(n< +<c;c=f=0): c="htaoins".index(y)+c*7: $1?n<<l+2: $2?n<<STDIN.getc: $3?f=1:(a=n.pop +;$4?$><<a. chr: $5?(n<<n[n.size-a.abs-1];a>0?n.delete_at(n.size-a-2):1):(b=n.pop; +$6?(n<<b/a ;n<<b%a): $7?n<<b-a: b!=0?(l=a-2;break):1))if y.chr=~ "(a)|(i)|(n)|(o)|(h)|(e)|(s)|(t)"};break if(l+=1)>=p.size||l<0}
        ... but I'm sure you can find one more byte... Stephen

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://146250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-03-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found