tacit programming - Why do I not get the correct answer for Euler 56 in J? -


I have solved the problems of Project Euler problems, mostly going back to Haskell, now I am going back and studying in J. As I am trying to solve in Jask

Currently, I am trying to solve I should emphasize that I already know what the correct answer is , because I have it in Haskell It has a very easy, trivial problem already resolved in the I will not answer here.

Here's my solution in Jammu:

 points =: ("." 0) @ ":" 0 each Digit =: adverb: 'u @: marks '0' NB I use it, so I made it a mechanism. Cartesian =: Adverb: '((# ~ #) U ($ ~ *: @ #))' & gt; / + / Each Digit x: ^ Cartesian>: 99 99 

This produces less number than desired result. In other words, this is somehow wrong. Because it is very straightforward and completely brutal force, I wonder.

The reason for this is that you are expanding application precision ( x: ) The game is too late. Switch to expanded precision, the first thing you do (like i. X: 99 ) and you have all your sets.

Another note regarding your Cartesian . You can see J's underlying:

  ^ / ~> : I.5 1 1 1 1 2 4 8 16 32 3 9 27 81 243 4 16 64 256 1024 5 25 125 625 3125, ^ / ~ & gt;: i.3 1 1 1 2 4 8 3 9 27 < / Code> 

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -