in reply to Symmetrical Numbers (GOLF)

okay, this looked like A LOT of fun, so i put my work aside to give this a try. here goes!
#!/usr/bin/perl -w my $ref = sym(10000); for my $key (sort {$a <=> $b} keys %$ref) { printf "%-10d%d\n",$key,$ref->{$key}; } sub sym { for(1..shift) { sub s{$_[0]==join"",reverse split//,$_[0]} if(&s($_)&&&s($_**2)){$s{$_}=$_**2} } \%s; }
which produces:
1 1 2 4 3 9 11 121 22 484 101 10201 111 12321 121 14641 202 40804 212 44944 1001 1002001 1111 1234321 2002 4008004
i'm quite pleased, for my first golf attempt, at

UPDATE

97 chars!

~Particle

nevermind the xp, remember the experience.

Replies are listed 'Best First'.
Re: Re: Symetrical Numbers (GOLF)
by particle (Vicar) on Jul 12, 2001 at 00:08 UTC
    a few changes, and viola! 79 chars.
    sub sym { for(1..pop){ sub s{$_[0]==reverse$_[0]} if(&s($_)&&&s($_**2)){$s{$_}=$_**2} } \%s; }

    ~Particle

    nevermind the xp, remember the experience.

Re: Re: Symetrical Numbers (GOLF)
by tachyon (Chancellor) on Jul 11, 2001 at 23:43 UTC

    Well done this is actually only 97 chars!! In golf all that counts is the bit within the curlies of the GOLF sub as noted. There are always inaccuracies in the counts thus the little scoring app:

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

    cheers

    tachyon

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