Hmm... the way that seems obvious to me seems to be less efficient than your approach:
kolakosky=: (# 2 1 $~ #)@]^:(> #)^:_&2 timespacex 'kolakosky 21717700' 0.933105 1.16183e9 Interestingly, the length of the seed sequence seems to have a disproportionate effect on the amount of space used: timespacex '21717700 (# 2 1 $~ #)@]^:(> #)^:_: 2 2 1 1' 0.946427 1.14925e9 timespacex '21717700 (# 2 1 $~ #)@]^:(> #)^:_: 2 2 1 1 2 1 2 2 1 2 2 1 1 2' 0.980988 1.10731e9 timespacex 'kolakosky 100' 3.07892e_5 10496 So going from a length 4 seed sequences to a length 14 sequence results in additional memory consumption of 4.19418e7 bytes of memory. And yet generating a length 100 kolakosky sequence costs only 10496 bytes of memory. I don't know if that is an inefficiency in J or some kind of crazy complexity imposed by the operating system. But since I get basically the same space numbers on different operating systems, I should probably assume that it's J. But I do not have any kind of algorithmic model for any part of J where that makes sense. So maybe this is a symptom of something else? If so, [chat forum question:] what could that be? Thanks, -- Raul On Thu, Jan 15, 2015 at 7:03 AM, R.E. Boss <[email protected]> wrote: > K=. 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 1 2 2 1 > 2 2 1 1 2 1 2 2 1 2 1 1 2 1 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 2 1 2 2 > 1 2 1 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 1 1 > is the start of a sequence where each i-th number gives the length of the > i-th substring of equal numbers. > Or in J > (}:#;.(2)~ 2~:/\]) K > 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 1 2 2 1 2 2 > 1 1 2 1 2 2 1 2 1 1 2 1 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 2 1 2 > > (Partial) equality from > ((]-: ({.~ #)) }:#;.(2)~ 2~:/\]) K > 1 > > I do have a way to generate them (not by hand), but what are other ways? > Elegant and lean svp. > > The first 21717701 items I generated in > ts 'genREB 2' > 0.9922127 8.0530995e8 > > > R.E. Boss > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
