in reply to Symmetrical Numbers (GOLF)

81 characters, and note that your counting code will break the count due to the extra sub (I counted the sub X{} characters for that in this case)
#234567890123456789012345678901234567890123456789012345678901234567890 sub r{$_[0]eq reverse$_[0]} #27 and... sub n{foreach(1..$_[0]){$a{$_}=$_*$_ if r($_)&&r($_*$_)};\%a} #61 - 7 + = 54 #81 total my $res = n(1000); print $_, " ", $res->{ $_ }, "\n" foreach ( keys %$res );

Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: Symetrical Numbers (GOLF)
by tachyon (Chancellor) on Jul 11, 2001 at 23:17 UTC

    Well actually.....it doesn't break the counting code. Only the first instance of sub foo { is removed courtesy of the ^ The \n are gone by the time the sub bit is removed and even if they were not there is no /m. Although the sub removed is sub r the result is correct. To satisfy the spec sub r shoud be contained within sub n as the spec was for a single sub to do the task not a whole app! The code says 82 BTW :-)

    use strict; my $code = <<'CODE'; sub r{$_[0]eq reverse$_[0]} sub n{foreach(1..$_[0]){$a{$_}=$_*$_ if r($_)&&r($_*$_)};\%a} } CODE $code =~ s/^\s+|\s+$//gm; $code =~ s/\n//g; $code =~ s/}$//; $code =~ s/^sub\s+(\w+)\s*{//; printf "Length of sub '$1' => %d chars", length $code; print "\n\n$code\n"; __END__

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Re: Symetrical Numbers (GOLF)
by MeowChow (Vicar) on Jul 11, 2001 at 23:30 UTC
    There's never a reason to use foreach in golf; it can always be replaced with a for.
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print