I used the following memoized code,
nextcol =: 3 : 0
if. 0=2|y do. -: y
else. >: 3*y
end.
)
colchain =: 3 : 0 M.
if. y=2 do. 1,2
else. chain=. colchain nextcol y
(>:0{chain),x:y>.1{chain
end.
)
but it took forever to generate the following I aborted it.
colchain"0 (2}.i.1000001)
I wonder if I did something wrong.
It seems to work if, for instance, you give
colchain"0 (2+i.9999)
Which makes me think the memoization isn't working
Even my slow Scheme interpreter gives the answer in 10 seconds or so, C++
in less than a second.
OTOH, old hands say that J isn't really meant for recursion. I wonder if
this problem should be tackled differently.
OK, I'm off to read Roger's post that Dan pointed to...
On 4 August 2014 17:30, mvillarino <[email protected]> wrote:
> 2014-08-04 14:12 GMT+02:00 Dan Bron <[email protected]>:
> > If you're OK with spoilers, have you seen Roger's Collatz Conjecture
> essay
> > on the Wiki?
> >
> > http://jsoftware.com/jwiki/Essays/Collatz%20Conjecture
> >
>
> ? I googled for information on a J spoiler... but no, I haven't found it.
> Thanks a lot !!!
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm