Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Spiral-matrix/VBScript/spiral-matrix.vb
Normal file
47
Task/Spiral-matrix/VBScript/spiral-matrix.vb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
Function build_spiral(n)
|
||||
botcol = 0 : topcol = n - 1
|
||||
botrow = 0 : toprow = n - 1
|
||||
'declare a two dimensional array
|
||||
Dim matrix()
|
||||
ReDim matrix(topcol,toprow)
|
||||
dir = 0 : col = 0 : row = 0
|
||||
'populate the array
|
||||
For i = 0 To n*n-1
|
||||
matrix(col,row) = i
|
||||
Select Case dir
|
||||
Case 0
|
||||
If col < topcol Then
|
||||
col = col + 1
|
||||
Else
|
||||
dir = 1 : row = row + 1 : botrow = botrow + 1
|
||||
End If
|
||||
Case 1
|
||||
If row < toprow Then
|
||||
row = row + 1
|
||||
Else
|
||||
dir = 2 : col = col - 1 : topcol = topcol - 1
|
||||
End If
|
||||
Case 2
|
||||
If col > botcol Then
|
||||
col = col - 1
|
||||
Else
|
||||
dir = 3 : row = row - 1 : toprow = toprow - 1
|
||||
End If
|
||||
Case 3
|
||||
If row > botrow Then
|
||||
row = row - 1
|
||||
Else
|
||||
dir = 0 : col = col + 1 : botcol = botcol + 1
|
||||
End If
|
||||
End Select
|
||||
Next
|
||||
'print the array
|
||||
For y = 0 To n-1
|
||||
For x = 0 To n-1
|
||||
WScript.StdOut.Write matrix(x,y) & vbTab
|
||||
Next
|
||||
WScript.StdOut.WriteLine
|
||||
Next
|
||||
End Function
|
||||
|
||||
build_spiral(CInt(WScript.Arguments(0)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue