I solved 84 Project Euler problems, mainly in Haskell. Now I come back and try to solve in J some of those that I have already decided in Haskell, as an exercise in learning J.
I am currently trying to solve Problem 56 . Let me emphasize that I already know that the correct answer , since I already solved it in Haskell. This is a very simple, trivial problem. I will not 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 leads to the fact that the number is less than the desired result. In other words, this is wrong. Does anyone know why? I am puzzled, as it is a fairly simple and complete brute force.
source
share