In Chat we had some posts about this subject and perhaps it is illustrating to
show the mathematical problem I solved last week using J.
You are invited to try yourself.
Given the sequence
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4
1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 ...
which is produced by
(,(1+>./),])^:(]`1:) 6
Interesting is, for a certain point between two numbers, see indication in next
line,
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 <>
1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 ...
to give the different numbers in increasing distance from this point.
If two different numbers have equal distance, then the left one goes first.
For the indicated (37th) point the numbers at increasing distance are
3 1 2 4 6 5
Exercise: generate the distance numbers for each of the 64 points in the
sequence above, check the table below and show that number 37 equals 3 1 2 4 6
5, in 9th row the first 6-tuple.
+-----------+-----------+-----------+-----------+
|1 2 3 4 5 6|1 2 3 4 5 6|2 1 3 4 5 6|1 3 2 4 5 6|
+-----------+-----------+-----------+-----------+
|3 1 2 4 5 6|1 2 3 4 5 6|2 1 4 3 5 6|1 4 2 3 5 6|
+-----------+-----------+-----------+-----------+
|4 1 2 3 5 6|1 2 4 3 5 6|2 1 3 4 5 6|1 3 2 4 5 6|
+-----------+-----------+-----------+-----------+
|3 1 2 5 4 6|1 2 3 5 4 6|2 1 5 3 4 6|1 5 2 3 4 6|
+-----------+-----------+-----------+-----------+
|5 1 2 3 4 6|1 2 5 3 4 6|2 1 3 5 4 6|1 3 2 5 4 6|
+-----------+-----------+-----------+-----------+
|3 1 2 4 5 6|1 2 3 4 5 6|2 1 4 3 5 6|1 4 2 3 5 6|
+-----------+-----------+-----------+-----------+
|4 1 2 3 6 5|1 2 4 3 6 5|2 1 3 4 6 5|1 3 2 4 6 5|
+-----------+-----------+-----------+-----------+
|3 1 2 6 4 5|1 2 3 6 4 5|2 1 6 3 4 5|1 6 2 3 4 5|
+-----------+-----------+-----------+-----------+
|6 1 2 3 4 5|1 2 6 3 4 5|2 1 3 6 4 5|1 3 2 6 4 5|
+-----------+-----------+-----------+-----------+
>|3 1 2 4 6 5|1 2 3 4 6 5|2 1 4 3 6 5|1 4 2 3 6 5|<
+-----------+-----------+-----------+-----------+
|4 1 2 3 5 6|1 2 4 3 5 6|2 1 3 4 5 6|1 3 2 4 5 6|
+-----------+-----------+-----------+-----------+
|3 1 2 5 4 6|1 2 3 5 4 6|2 1 5 3 4 6|1 5 2 3 4 6|
+-----------+-----------+-----------+-----------+
|5 1 2 3 4 6|1 2 5 3 4 6|2 1 3 5 4 6|1 3 2 5 4 6|
+-----------+-----------+-----------+-----------+
|3 1 2 4 5 6|1 2 3 4 5 6|2 1 4 3 5 6|1 4 2 3 5 6|
+-----------+-----------+-----------+-----------+
|4 1 2 3 5 6|1 2 4 3 5 6|2 1 3 4 5 6|1 3 2 4 5 6|
+-----------+-----------+-----------+-----------+
|3 1 2 4 5 6|1 2 3 4 5 6|2 1 3 4 5 6|1 2 3 4 5 6|
+-----------+-----------+-----------+-----------+
Now the question is, suppose you have a sequence of length <: 2^100, what is
the 100-tuple of numbers closest to, say, point
913666114835851906990879566194 (= ?. 2^100x) ?
My answer is
48 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 49 53 50 51 52 55 54 58 56 57 59 61
60 62 64 63 67 65 66 72 68 69 70 71 74 73 75 76 78 77 81 79
80 82 84 83 85 87 86 92 88 89 90 91 93 96 94 95 99 97 98 100
I checked the algorithm with all 1024 10-tuples from the sequence
(,(1+>./),])^:(]`1:) 10
What rests (for me) is to prove the program to be correct.
R.E. Boss
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm