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

... ie restrict the base 10 verb to base 2 palindromes

A bit more programming time involved, though.  And
Roger's Razor (along the lines of "it's not worth
striving for trivial time improvements") might apply,
according to taste.

M

----- Original Message -----
From: Bruno <[EMAIL PROTECTED]>
Date: Thursday, June 28, 2007 5:42 pm
Subject: [Jprogramming] Project Euler, problem 36
To: [email protected]

Hey, I'm currently doing Project Euler's problem 36, a rather simple
problem. The thing is I've just started learning J and I'm having some
problems finishing this problem...

Problem 36
31 January 2003

The decimal number, 585 = 10010010012 (binary), is palindromic in both
bases.

Find the sum of all numbers, less than one million, which are palindromic in
base 10 and base 2.

[snipped the rest of Bruno's post - Mike]
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to