in reply to Re: Symetrical Numbers (GOLF)
in thread Symmetrical Numbers (GOLF)

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

Replies are listed 'Best First'.
Re: Re: Re: Symetrical Numbers (GOLF)
by MeowChow (Vicar) on Jul 12, 2001 at 00:15 UTC
    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