[Jprogramming] Project Euler, problem 36

Raul Miller rauldmiller at gmail.com
Fri Jun 29 20:02:38 HKT 2007


On 6/29/07, Mike Day <mike_liz.day at tiscali.co.uk> 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


More information about the Programming mailing list