The two solutions are shown below. Each is followed by the set of successive intermediate results; for example 1-2=-1, then -1+3=2, and 2/4=0.5, etc.
1-2+3/4*5*6-7/8+9
-1
2
0.5
2.5
15
8
1
10
1/2*3-4+5*6-7/8+9
0.5
1.5
-2.5
2.5
15
8
1
10
DefDbl A-Z
Dim crlf$, ct(4), s$, v, h(9)
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr(13) + Chr(10)
s$ = "1": v = 1
addOn 2
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sub addOn(wh)
Dim ctsave(4)
For i = 1 To 4
vsave = v: ssave$ = s
For j = 1 To 4
ctsave(j) = ct(j)
Next
Select Case i
Case 1
v = v + wh
s = s + "+"
ct(1) = ct(1) + 1
Case 2
v = v - wh
s = s + "-"
ct(2) = ct(2) + 1
Case 3
v = v * wh
s = s + "*"
ct(3) = ct(3) + 1
Case 4
v = v / wh
s = s + "/"
ct(4) = ct(4) + 1
End Select
h(wh) = v
s = s + LTrim(Str(wh))
If ct(i) <= 2 Then
If wh = 9 Then
If Abs(v - 10) < 0.000000001 Then
Text1.Text = Text1.Text & s & crlf
For j = 2 To 9
Text1.Text = Text1.Text & h(j) & crlf
Next
Text1.Text = Text1.Text & crlf
End If
Else
addOn wh + 1
End If
End If
s = ssave: v = vsave
For j = 1 To 4
ct(j) = ctsave(j)
Next
Next
End Sub
|
Posted by Charlie
on 2018-05-26 13:00:57 |