48 lines
1.4 KiB
Text
48 lines
1.4 KiB
Text
Module Lib1 {
|
|
Module Global PrintArray(&Ar()) {
|
|
if dimension(Ar())<>2 then Error "This is for 2D arrays"
|
|
integer i, j, n=dimension(Ar(),1), n1=dimension(Ar(),2)
|
|
for i=1 to n
|
|
for j=1 to n1
|
|
print Ar(i, j),
|
|
next
|
|
print
|
|
next
|
|
}
|
|
Function Global MakeArray(n as integer=5) {
|
|
dim a(1 to n, 1 to n) as integer=0
|
|
integer i=1, j=1, z, t1=1
|
|
boolean ch=true
|
|
for z=0 to n*n-1
|
|
if ch then a(i,j)=z else a(j,i)=z
|
|
j++
|
|
if j>t1 then t1++: j=1:i=t1: ch~ else i--
|
|
if i<1 then i=t1 else.if i>n then i=n: j++
|
|
if j>n then j=i+2: i=n:ch~
|
|
next
|
|
=a() // return array (as a pointer)
|
|
}
|
|
}
|
|
Module Zig_Zag_Matrix (n as integer=5) {
|
|
Pen 15 {Report "matrix "+n+"x"+n}
|
|
integer old_column=tab
|
|
Print $(,4) // set column to 4 chars
|
|
if random(1,2)=2 then
|
|
dim ret()
|
|
ret()=makeArray(n) // this get a copy
|
|
else
|
|
object a=makeArray(n) // but this get the copy of pointer
|
|
link a to ret() // ret() is reference to a, to array
|
|
end if
|
|
PrintArray &ret()
|
|
Print $(,old_column)
|
|
}
|
|
Inline Code Lib1 // just execute the code from module lib1 like was here
|
|
Form 60, 36 \\ console 60x36 characters
|
|
Report 2, "Zig-zag matrix" // 2 for center
|
|
Pen 14 {Zig_Zag_Matrix 1}
|
|
Pen 11 {Zig_Zag_Matrix 2}
|
|
Pen 14 {Zig_Zag_Matrix 3}
|
|
Pen 11 {Zig_Zag_Matrix 4}
|
|
Pen 14 {Zig_Zag_Matrix 5}
|
|
Pen 11 {Zig_Zag_Matrix 10}
|