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. ----- 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. > > (Please note that the palindromic number, in either base, may > not include > leading zeros.) > > One of the things I can't do is one line programs, I always have > to break it > up in several pieces and variables, because if I don't my > machine will > usually lock up. In this problem I can't run my functions trough > the range > of 1-1e6, my machine always jams. > > I'll ask your help here in how would I make an optimized > algorithm that only > have to run once... > > > I have created a couple functions: > > To see if the number is a palindrome: > isp=: verb : 'y = 10 #. |. "."0": y' > To see if the number is a palindrome in binary: > isp2=: '(10 #. #: y) = (10 #. |. > #: y)' NB. this one actually dosen't > works =( > (10 #. #: 585) = (10 #. |. #: > 585) NB. but doing like this works > > In the second case, for instance, I do the same operation twice > (#: 585) but > I don't know how to optimize that.... > > If those functions worked here's how would I continue: > > First go trough 1-1e6 and do isp for each number NB. the machine > locked up > here > Store that in a variable > Grab that variable and do a # 1e6 with them > Store all the palindromes in base 2 in a variable > Now run isp2 for all the elements of that list > Do a # with those elements and the variable that stored the > palindromes in > base two > +/ all the remaining itens > > So as you can see my solution is far from optimal or "clean", > and it dosen't > even works =( > I wanted to run the loop only once, and store the values that are > palindromes in both bases without having to do the (0 1 0 ... # > elements).If possible without building functions and other > variables. And optimizing > my code, without having to do the same operations twice, etc. > > Please don't think I'm asking for help here to have the problem > solved for > me, It's a rather simple problem and I could do it in C, I'm > here asking for > your help because I wan't to learn J. > > Thanks in advance and sorry for the long and unorganized post, > Bruno. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
