Write a program or function that takes in a positive integer N and outputs the first N numbers of this amplifying zigzag pattern, using only the lines needed:
26
25 27 .
10 24 28 .
9 11 23 29 .
2 8 12 22 30 44
1 3 7 13 21 31 43
4 6 14 20 32 42
5 15 19 33 41
16 18 34 40
17 35 39
36 38
37
So, if N is 1
the output is
1
If N is 2
, the output is
2
1
If N is 3
the output is
2
1 3
If N is 4
the output is
2
1 3
4
If N is 10
the output is
10
9
2 8
1 3 7
4 6
5
If N is 19
the output is
10
9 11
2 8 12
1 3 7 13
4 6 14
5 15 19
16 18
17
and so on.
Notes
Each peak or trough of the zigzag reaches its point one more line away from the line with the
1
on it than the previous peak or trough.N is not limited to
44
. The zigzag grows in the same pattern and larger N should be supported.Numbers with multiple digits should only "touch" at their corners, as depicted. Make sure this works when N is
100
and above.There should be no empty (or space only) lines in the output except one optional trailing newline.
Any line may have any amount of trailing spaces.
Scoring
The shortest code in bytes wins. Tiebreaker is earlier answer.