How to resolve the algorithm Zig-zag matrix step by step in the Maple programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Zig-zag matrix step by step in the Maple programming language
Table of Contents
Problem Statement
Produce a zig-zag array.
A zig-zag array is a square arrangement of the first N2 natural numbers, where the
numbers increase sequentially as you zig-zag along the array's anti-diagonals.
For a graphical representation, see JPG zigzag (JPG uses such arrays to encode images).
For example, given 5, produce this array:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Zig-zag matrix step by step in the Maple programming language
Source code in the maple programming language
zigzag1:=proc(n)
uses ArrayTools;
local i,u,v,a;
u:=Replicate(<-1,1>,n):
v:=Vector[row](1..n,i->i*(2*i-3)):
v:=Reshape(,2*n):
a:=Matrix(n,n):
for i to n do
a[...,i]:=v[i+1..i+n];
v+=u
od:
a
end:
zigzag2:=proc(n)
local i,v,a;
a:=zigzag1(n);
v:=Vector(1..n-1,i->i^2);
for i from 2 to n do
a[n+2-i..n,i]-=v[1..i-1]
od;
a
end:
zigzag1(6);
zigzag2(6);
You may also check:How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Bitmap step by step in the D programming language
You may also check:How to resolve the algorithm Variable size/Get step by step in the Pop11 programming language
You may also check:How to resolve the algorithm Logical operations step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the HolyC programming language