我正在尝试编写一些vba,将打印满足以下约束的值:
b * k = t * k
lambda = r * (k - 1) / (t - 1)
,其中(t - 1) >= (k - 1)
&lambda
必须为整数。
算法如下:
Sub BIBDs()
Dim t, b, k, r As Integer
Dim lambda As String
For t = 2 To 50
For b = 2 To 20
For r = 1 To 20
For k = 3 To 5
If b * k = t * k & (t - 1) >= (k - 1) Then
lambda = r * (k - 1) / (t - 1)
If lambda = Int(lambda) Then
Debug.Print t, b, r, k, lambda
End If
End If
Next k
Next r
Next b
Next t
End Sub
"立即"窗口中不打印任何内容。我不确定是算法还是我的打印方法有问题。具体来说,我不确定我是否正确地检查了,是一个整数。
Try
If b * k = t * k And (t - 1) >= (k - 1) Then
不是If b * k = t * k & (t - 1) >= (k - 1) Then
,操作符在VBA中与逻辑不一样,操作符: https://msdn.microsoft.com/en-us/library/wfx50zyk.aspx