Why do I not get the correct answer for Euler 56 in J?
Posted
by Gregory Higley
on Stack Overflow
See other posts from Stack Overflow
or by Gregory Higley
Published on 2010-06-15T07:47:52Z
Indexed on
2010/06/15
7:52 UTC
Read the original article
Hit count: 336
I've solved 84 of the Project Euler problems, mostly in Haskell. I am now going back and trying to solve in J some of those I already solved in Haskell, as an exercise in learning J.
Currently, I am trying to solve Problem 56. Let me stress that I already know what the right answer is, since I've already solved it in Haskell. It's a very easy, trivial problem. I will not give the answer here.
Here is my solution in J:
digits =: ("."0)":"0 eachDigit =: adverb : 'u@:digits"0' NB. I use this so often I made it an adverb. cartesian =: adverb : '((#~ #) u ($~ ([:*~#)))' >./ +/ eachDigit x: ^ cartesian >: i. 99
This produces a number less than the desired result. In other words, it's wrong somehow. Any J-ers out there know why? I'm baffled, since it's pretty straightforward and totally brute force.
© Stack Overflow or respective owner