On 6/29/07, Mike Day <[EMAIL PROTECTED]> wrote:
Comment embedded with Roger's spoiler ...
Mike
Roger Hui wrote:
> Spoiler alert:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> This is the solution I had in June 2005:
> +/ I. ((-:|.)@#: *. (-:|.)@":)"0 i.1e6
>
> The thinking was that (-:|.)@": is fast for testing
> palindromes in base 10 and (-:|.)@#. in base 2
>
If comparison of performance with C is an issue, you
can save a bit of J time with
+/(* ((-:|.)@#:"0)) (#~((-:|.)@":"0)) i. 1e6
... ie restrict the base 2 verb to base 10 palindromes
and this next is slightly faster again
+/(* ((-:|.)@":"0)) (#~((-:|.)@#:"0)) i. 1e6
Note also that all base 2 palindromes must be odd.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm