第16講 魔方陣作成の高速化(数万倍へ)
第10話 Ver.2の完成!
Dim mah(6, 6) As Byte, x(36) As Byte, y(36) As Byte, p(36) As Byte
Dim n As Byte, cn As Integer
Private Sub CommandButton1_Click()
Dim i, j As Integer
n = Cells(3, 8)
Rnd (-1)
If n = 4 Then Randomize (219)
If n = 5 Then Randomize (56)
If n = 6 Then Randomize (400)
syokika
zhy
sk = 0
cn = 0
ms (0)
End Sub
Sub syokika()
Dim i As Byte
For i = 0 To n * n - 1
p(i) = 0
Next
sk = 0
cn = 0
End Sub
・
・
・
Sub ms(g As Byte)
Dim i As Integer, j As Byte, k As Byte, a As Byte, b As Byte, w As Byte,
h As Byte
Dim ii As Integer, iii As Integer, kk As Byte
a = x(g)
b = y(g)
ii = n * n * Rnd
If n = 4 Then kk = 7
If n = 5 Then kk = 24
If n = 6 Then kk = 13
If n = 3 Then kk = 1
For i = 0 To n * n - 1
iii = (ii + kk * i) Mod n * n
mah(b, a) = iii + 1
h = 0
If p(mah(b, a) - 1) = 1 Then GoTo tobi
If p(mah(b, a) - 1) = 0 Then
p(mah(b, a) - 1) = 1
h = 1
End If
・
・
・
tobi:
If h = 1 Then p(mah(b, a) - 1) = 0
Next
End Sub
Ver.2完成ファイル
第9話へ 第17講第1話へ
VBA講義第1部へ
vc++講義へ
vb講義へ
VB講義基礎へ
初心者のための世界で一番わかりやすいVisual C++入門基礎講座へ
初心者のための世界で一番わかりやすいVisual Basic入門基礎講座へ
数学研究室に戻る