Rem ==== 九連環問題求解 ====
Rem 注意─有兩個optionbutton元件
Dim k As Integer
Private Sub CommandButton1_Click()
Num = Cells(1, 1) '環數
k = 1
If (OptionButton1.Value) Then '上環
Cells(2, 1) = "MOVE " & Num & " RINGS UP"
Call Up(Num)
Else '下環
Cells(2, 1) = "MOVE " & Num & " RINGS DOWN"
Down (Num)
End If
Cells(k + 2, 1) = "IT TAKES " & k & " MOVES"
End Sub
Sub Up(nn)
If nn > 0 Then
Call Up(nn - 1)
Call Down(nn - 2)
Cells(k + 2, 1) = "RING " & nn & " UP"
k = k + 1
Up (nn - 2)
End If
End Sub
Sub Down(nn)
If nn > 0 Then
Call Down(nn - 2)
Cells(k + 2, 1) = "RING " & nn & " DOWN"
k = k + 1
Call Up(nn - 2)
Call Down(nn - 1)
End If
End Sub