用5,6,3,3算24点游戏答案有多少种
去掉重复的,一共六种,如下:
5*(3+3)-6
5*6-3-3
6*(3*3-5)
6*(5-3/3)
3*5+3+6
(6+5-3)*3
我认为 ((6-3)+5)*3 和 ((5-3)+6)*3 是一种情况,即(5+6-3)*3
可以在Excel中做宏,把重复的去掉(考虑到某种情况,会有答案是-24的结果),得出六种情况:
Sub compute()
Dim m(4) As String
Dim j1, j2, j3, j4 As Integer
m(1) = "3"
m(2) = "3"
m(3) = "5"
m(4) = "6"
Worksheets("Sheet1")。 Ce...全部
去掉重复的,一共六种,如下:
5*(3+3)-6
5*6-3-3
6*(3*3-5)
6*(5-3/3)
3*5+3+6
(6+5-3)*3
我认为 ((6-3)+5)*3 和 ((5-3)+6)*3 是一种情况,即(5+6-3)*3
可以在Excel中做宏,把重复的去掉(考虑到某种情况,会有答案是-24的结果),得出六种情况:
Sub compute()
Dim m(4) As String
Dim j1, j2, j3, j4 As Integer
m(1) = "3"
m(2) = "3"
m(3) = "5"
m(4) = "6"
Worksheets("Sheet1")。
Cells(3, 1)。Value = 0
For j1 = 1 To 4
For j2 = 1 To 4
For j3 = 1 To 4
For j4 = 1 To 4
If j1 <> j2 And j1 <> j3 And j1 <> j4 And j2 <> j3 And j2 <> j4 And j3 <> j4 Then
Call point24(m(j1), m(j2), m(j3), m(j4))
End If
Next
Next
Next
Next
End Sub
Function point24(a As String, b As String, c As String, d As String)
Dim i1, i2, i3 As Integer
Dim s(4, 4, 4) As String
Dim fuhao As String
For i1 = 1 To 4
For i2 = 1 To 4
For i3 = 1 To 4
s(i1, i2, i3) = a
Select Case i1
Case 1
fuhao = "+"
Case 2
fuhao = "-"
Case 3
fuhao = "*"
Case 4
fuhao = "/"
End Select
s(i1, i2, i3) = s(i1, i2, i3) & fuhao & b
Select Case i2
Case 1
fuhao = "+"
Case 2
fuhao = "-"
Case 3
fuhao = "*"
Case 4
fuhao = "/"
End Select
s(i1, i2, i3) = "(" & s(i1, i2, i3) & ")" & fuhao & c
Select Case i3
Case 1
fuhao = "+"
Case 2
fuhao = "-"
Case 3
fuhao = "*"
Case 4
fuhao = "/"
End Select
s(i1, i2, i3) = "(" & s(i1, i2, i3) & ")" & fuhao & d
Worksheets("Sheet1")。
Cells(1, 1)。Value = "=" & s(i1, i2, i3)
Worksheets("Sheet1")。Cells(2, 1)。Value = s(i1, i2, i3)
Worksheets("Sheet1")。
Cells(3, 1)。Value = Worksheets("Sheet1")。Cells(3, 1)。Value + 1
If CLng(Worksheets("Sheet1")。Cells(1, 1)。
Value) = 24 Or CLng(Worksheets("Sheet1")。Cells(1, 1)。Value) = -24 Then
Worksheets("Sheet1")。Cells(2, 1)。
Copy
MsgBox ("I got it!")
End If
Next
Next
Next
End Function
。收起