I'd like to know about a nice way to generate the Gijswijt's sequence,
which is sequence A090822 in the OEIS
("http://www.research.att.com/~njas/sequences/A090822")
This sequence starts with an 1 and every element is the largest k for
which that element is immediately preceded by k repeated copies of
some subsequence. The sequence starts like this:
1 1 2 1 1 2 2 2 3
Eg. the element at index 5 is 2 because it's preceded by 2 repetitions
of (,1); the next element is 2 because it's preceded by 2 repetitions
of (1 1 2); the next is 2 because it's preceded by 2 repetitions of
(,2).
More information about this sequence can be found at the OEIS entry,
and the articles it links to
("http://www.cs.uwaterloo.ca/journals/JIS/VOL10/Sloane/sloane55.pdf"
in particular).
Here is some J code I wrote that generates (I hope) this sequence.
gij=: 3 :'(,[:>:[:>./ -@:>:@:i.@:<.@:-:@:# (0 i.~2=/\])@(<\) |.)^:(y-2)] 1 1'
gij 35
1 1 2 1 1 2 2 2 3 1 1 2 1 1 2 2 2 3 2 1 1 2 1 1 2 2 2 3 1 1 2 1 1 2 2
4 i.~ gij 250
219
The last line shows that the first 4 appears at index 219.
Please show me a better way to generate this sequence programmatically.
(Ps. thanks for Pelikán József for mentioning this sequence today.)
Thanks,
Ambrus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm