N年前的习作,效率不高,但好理解: '易知九宫图中间为5,关于中心对称位置之和为10,分析如下: ' a b c ' d 5 10-d
' 10-c 10-b 10-a
'if a is an odd,c is an odd ,then 10-a is an odd,10-c is odd,so b,d,10-d,10-b are all odds(paradox) 'if a is an odd,c is an even ,then 10-a is an odd,10-c is even,so b,d,10-d,10-b are all evens(paradox) 'if a is an even,c is an odd ,then 10-a is an even,10-c is odd,so b,d,10-d,10-b are all evens(paradox) 'if a is an even,c is an even ,then 10-a is an even,10-c is even,so b,d,10-d,10-b are all odds(maybe) 'so a ,c must be evens; b,d must be odds Dim nine As New Collection Private Sub Form_Load() Dim a As Integer, b As Integer, c As Integer, d As Integer, i As Integer For a = 2 To 8 Step 2 For b = 1 To 9 Step 2 For c = 2 To 8 Step 2 For d = 1 To 9 Step 2 If a + b + c = 15 And a + d - c = 5 And a + c <> 10 And b + d <> 10 And b <> 5 And d <> 5 Then nine.Add StrConv(a & b & c & vbCrLf & d & "5" & (10 - d) & vbCrLf & (10 - c) & (10 - b) & (10 - a), vbWide) '全角显示 Next: Next: Next: Next For i = 1 To nine.Count MsgBox nine(i), 64, "九宫图之" & i Next End Sub
|