37 lines
955 B
Plaintext
37 lines
955 B
Plaintext
' FB 1.05.0 Win64
|
|
|
|
Sub equilibriumIndices (a() As Integer, b() As Integer)
|
|
If UBound(a) = -1 Then Return '' empty array
|
|
|
|
Dim sum As Integer = 0
|
|
Dim count As Integer = 0
|
|
For i As Integer = LBound(a) To UBound(a) : sum += a(i) : Next
|
|
Dim sumLeft As Integer = 0, sumRight As Integer = 0
|
|
|
|
For i As Integer = LBound(a) To UBound(a)
|
|
sumRight = sum - sumLeft - a(i)
|
|
If sumLeft = sumRight Then
|
|
Redim Preserve b(0 To Count)
|
|
b(count) = i
|
|
count += 1
|
|
End If
|
|
sumLeft += a(i)
|
|
Next
|
|
End Sub
|
|
|
|
Dim a(0 To 6) As Integer = { -7, 1, 5, 2, -4, 3, 0 }
|
|
Dim b() As Integer
|
|
equilibriumIndices a(), b()
|
|
If UBound(b) = -1 Then
|
|
Print "There are no equilibrium indices"
|
|
ElseIf UBound(b) = LBound(b) Then
|
|
Print "The only equilibrium index is : "; b(LBound(b))
|
|
Else
|
|
Print "The equilibrium indices are : "
|
|
For i As Integer = LBound(b) To UBound(b) : Print b(i); " "; : Next
|
|
End If
|
|
|
|
Print
|
|
Print "Press any key to quit"
|
|
Sleep
|