in reply to Symmetrical Numbers (GOLF)

66 chars:
sub mc_sym { \%{{map{(reverse eq$_&&($x=$_*$_)eq reverse$x)?($_,$x):()}1..pop}} }
61, borrowing from no_slogan :)
sub mc_sym { +{map{(reverse==$_&&($x=$_*$_)==reverse$x)?($_,$x):()}1..pop} }
59 with some bit-twiddling:
sub mc_sym { +{map{(reverse^$_||($x=$_*$_)^reverse$x)?():($_,$x)}1..pop} }
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: Re: Symetrical Numbers (GOLF)
by chipmunk (Parson) on Jul 12, 2001 at 00:06 UTC
    You can get that down to 56 by optimizing the parens and switching to bitwise-or:
    sub symmetrical_squares { +{map reverse^$_|reverse($x=$_**2)^$x?():($_,$x),0..pop} }
    BTW, I note that the description says to start with 0, but the example output starts with 1... I decided to start with 0. 0*0 = 0, and both 0 and 0 are symmetrical, so 0 should be in the output. :)
      I think you may have seen my golf just before I posted a fix. The bitwise OR can't be used here in this way, since it has the same precedence as XOR, and this leads to a rather subtle bug (notice that your sub returns 26 as a symmetrical number). But your idea still applies; here's a working one at 56:
      +{map$_^reverse||reverse($x=$_**2)^$x?():($_,$x),0..pop}
      update: Switching from XOR to subtraction, however, permits the use a bitwise OR, saving a char, at 55:
      +{map$_-reverse|reverse($x=$_**2)-$x?():($_,$x),0..pop}
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print