已完成, 請試一試以下的網址:
http://www.geocities.com/shin_bingo_dog/Random_addition_1.xls
program 如下:
Dim a(6)
Sub Macro1()
'
x1 = Cells(1, 1): x2 = Cells(2, 1): x3 = Cells(3, 1)
x4 = Cells(4, 1): x5 = Cells(5, 1): x6 = Cells(6, 1)
y = Cells(1, 2)
st = 8
For i1 = 0 To 1
For i2 = 0 To 1
For i3 = 0 To 1
For i4 = 0 To 1
For i5 = 0 To 1
For i6 = 0 To 1
a(1) = i1: a(2) = i2: a(3) = i3: a(4) = i4: a(5) = i5: a(6) = i6
s = x1 * i1 + x2 * i2 + x3 * i3 + x4 * i4 + x5 * i5 + x6 * i6
If s = y Then
c = 1
st = st + 1
For i = 1 To 6
If a(i) = 1 Then
Cells(st, c) = Cells(i, 1)
Cells(st, c + 1) = "+"
c = c + 2
End If
Next i
Cells(st, c - 1) = "="
Cells(st, c) = s
End If
Next i6
Next i5
Next i4
Next i3
Next i2
Next i1
End Sub
基本上, 因有兩個 100, 所以solution 有重覆item 出現. 如有需要, 可加多一兩句, 使重覆item 只出現一次.
2009-06-15 10:06:57 補充:
可以在我給出的網址 download 我的 excel file.
在 工具 --> 巨集 --> visual basic 編輯器
就會找到這個 program 了.