It's easier to see if we stick to indices rather than an arbitrary string.
Indices of elements in descending vertical columns in the zig-zag layout
for m rows belong to
(i.m) + 2 * (m-1) * i. n ,
where n is sufficient to exhaust the array,
and indices of the RISING diagonals are, for m>1,
m + (i.m-2) + 2 * (m-1) * i.n ,
but we really need them in the descending direction, so we require
m + (i.2-m) + 2 * (m-1) * i.n,
so the indices in the final array will be :
top row:
(1 >. 2*(m-1)) * i.n
intermediate rows 0<k<m, (if m>2) :
k, (k+2*(m-(1+k))), ... , (k + 2*i*(m-1)),(k + (2*i*(m-1)) +
2*(m-(1+k))) ...
bottom row, if m>1:
(m-1) + 2*(m-1) * i.n
It's easier to see with a specific example; eg for m = 4:
The zigzag tableau:
0 8 16
1 7 9 15 17
2 6 10 14 18
3 5 11 13 19
4 12 ....
becomes:
0 8 16 ... 1 7 9 15 17 ... 2 6 10 14 18 ... 3 5 11 13 19 ... 4 12 ...
which the various verbs do return:
4 cv i.20
0 6 12 18 1 5 7 11 13 17 19 2 4 8 10 14 16 3 9 15
or, for a longer string,
4 cv i.30
0 6 12 18 24 1 5 7 11 13 17 19 23 25 29 2 4 8 10 14 16 20 22 26 28 3 9
15 21 27
No doubt Roger could "prove" the result as a J theorem.
It's a beautiful leap of insight to see that labelling the tableau as
follows:
0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 ....
shows that the much simpler
/: 0 1 2 3 4 3 2 1 0 1 2 3 ...
does the trick.
Any use,
Mike
On 29/09/2016 22:19, David Lambert wrote:
Foul mood day, beware!
1) there are no examples for other than 3 rows. How can you tell if a
solution is correct in general?
2) Pepe proved, by tacitly implementing a Turing machine, that tacit j
is Turing complete. Hence the problem can be solved tacitly if it's
amenable to machine solution.
On 09/28/2016 08:00 AM, programming-requ...@forums.jsoftware.com wrote:
Date: Wed, 28 Sep 2016 00:59:06 +0000 (UTC)
From: "'Jon Hough' via Programming"<programm...@jsoftware.com>
To:<programm...@jsoftware.com>
Subject: Re: [Jprogramming] Zig Zag problem
Message-ID:<278656873.5830960.1475024346...@mail.yahoo.com>
Content-Type: text/plain; charset=UTF-8
Yes, thanks. I didn't think this problem could be solved purely
tacitly, but seems I was wrong.
By the way, small nitpick, but your solution fails for the case of
number of rows = 1:
1 tconvert 'SOMETEXT'
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm