in reply to 20 bytes from cLive ;-)
in thread Is Perl less compact than Ruby? (Kind of competition)

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?

Replies are listed 'Best First'.
Re: err, i miscounted
by locked_user mtve (Deacon) on Feb 18, 2002 at 21:47 UTC

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

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

      We're back to 356.
      /o/&&print+chr(p); --- /o/&&print+chr p;

      Update: I'm not positive, as I don't know the language, but I think the following can also be done:

      $0=p,$_=p,v int$_/$0,$_%$0if/e/; --- v int($_=p)/($0=p),$_%$0if/e/;
      Saves 2 characters. As I only have one very simple test program, it may not be exercising that spot very well.
      ** FUNGICIDE ** -- Fungus calendar -- CURTSEY: Fungal toe! Fungal toe! Fungal hoe! -- (Burnt programmer nucleus) Ooooooo! CRUDDY 2nd TOE: Nine(!) fungal hyaena toe5! Dungy alfalfa, penalty superlunary -- Oh, blubber! Ooooooo!

      Update2: With the same caveat ...

      /s/&&v-(p)+p; --- /s/&&v+p-p;

      ------
      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.

        Thanks!

        /o/&&print+chr p;

        early it was warning "Use of "chr" without parens is ambiguous" on chr pop @n

        /s/&&v+p-p;

        nope, p has side effect of popping stack, so it breaks the logic.

Re: err, i miscounted
by Anonymous Monk on Feb 18, 2002 at 22:17 UTC
    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