有人可以解释为什么这不起作用吗?(意味着变量 colorChange 在整个函数中保持不变)
每个数组(leftRing 和 rightRing 具有从 1 到 4 的整数值)
Private Sub Solve_Click(sender As System.Object, e As System.EventArgs) Handles Solve.Click
countColorChangesInRings(colorChanges)
RotateLeftRingClockwise()
countColorChangesInRings(colorChanges)
End Sub
Sub countColorChangesInRings(ByRef var As Integer)
Dim colorChangesLeft As Integer = 0
Dim colorChangesRight As Integer = 0
Dim totalChanges As Integer = 0
' Count Color Changes in Left Ring
For i = 1 To 20
If (i = 20) Then
If (leftRing(i) <> leftRing(1)) Then
colorChangesLeft += 1
End If
Else
If (leftRing(i) <> leftRing(i + 1)) Then
colorChangesLeft += 1
End If
End If
Next
' Count Color Changes in Right Ring
For i = 1 To 20
If (i = 20) Then
If (rightRing(i) <> rightRing(1)) Then
colorChangesRight += 1
End If
Else
If (rightRing(i) <> rightRing(i + 1)) Then
colorChangesRight += 1
End If
End If
Next
totalChanges = colorChangesLeft + colorChangesRight
var = totalChanges
End Sub
Sub RotateLeftRingClockwise()
Dim temp As Integer = leftRing(1)
' Rotates Rings clockwise direction
For i = 1 To 20
If (i = 20) Then
leftRing(i) = temp
Else
leftRing(i) = leftRing(i + 1)
End If
Next
End Sub