The program at bottom is based on the one for the "three fours" puzzle, except of course it uses four 4's. Also it does not use double factorials or subfactorials, though the setup of those is performed at the beginning of the program--that doesn't do any harm.
As in "three fours", .4. in the algebraic expression column represents .4 with a bar over the 4, or 4/9.
The left column has, separated by spaces, the number represented, how many representations of that number were found using four 4's and the RPN representation of one shortest such formula. The last column shows the algebraic notation representation of the four-4's formula. The formula that is shortest when represented in RPN (or one of those tied for shortest). Seven numbers had zero ways of being produced.
1 1481358 44,44/ 44/44
2 152205 44,4+,4!/ (44+4)/(4)!
3 39674 44,4/,4v-v sqrt((44/4-sqrt(4)))
4 81584 44,4-,4!-v sqrt((44-4-(4)!))
5 43137 44,4!-,4/ (44-(4)!)/4
6 59911 44,4-,4-v sqrt((44-4-4))
7 3665 44,4/,4- 44/4-4
8 18470 44,4-,4!+v sqrt((44-4+(4)!))
9 4807 44,4/,4v- 44/4-sqrt(4)
10 3684 44,4-,4/ (44-4)/4
11 324 44,4,4*v/ 44/sqrt((4*4))
12 14979 44,4+,4/ (44+4)/4
13 411 44,4/,4v+ 44/4+sqrt(4)
14 1017 4,4+,4+,4v+ 4+4+4+sqrt(4)
15 480 44,4/,4+ 44/4+4
16 16673 44,4-,4!- 44-4-(4)!
17 762 44,4!+,4/ (44+(4)!)/4
18 2624 44,4v/,4- 44/sqrt(4)-4
19 591 4!,4-,4,4/- (4)!-4-4/4
20 5149 44,4-,4v/ (44-4)/sqrt(4)
21 1092 44,4v-,4v/ (44-sqrt(4))/sqrt(4)
22 4698 44,4/,4v* (44/4)*sqrt(4)
23 11072 44,4v+,4v/ (44+sqrt(4))/sqrt(4)
24 151711 44,4+,4!- 44+4-(4)!
25 21694 4,4/,4+,4^v sqrt((4/4+4)^4)
26 8262 44,4v/,4+ 44/sqrt(4)+4
27 2368 4,4,4/-,4!+ 4-4/4+(4)!
28 7044 44,4,4*- 44-4*4
29 1413 4,4/,4+,4!+ 4/4+4+(4)!
30 3051 4,4+,4*,4v- (4+4)*4-sqrt(4)
31 52 4,4!+,4/,4!+ (4+(4)!)/4+(4)!
32 4079 44,4!,4v/- 44-(4)!/sqrt(4)
33 124 44,4,9/,4*v/ 44/sqrt(((.4.)*4))
34 438 44,4!+,4v/ (44+(4)!)/sqrt(4)
35 102 44,4/,4!+ 44/4+(4)!
36 5711 44,4-,4- 44-4-4
37 101 4,4,4,9//+,4!+ 4+4/(.4.)+(4)!
38 291 44,4-,4v- 44-4-sqrt(4)
39 35 4,4!+,4,9//,4!- (4+(4)!)/(.4.)-(4)!
40 1225 44,4,4*v- 44-sqrt((4*4))
41 16 4,4+!,4!+,4!/v sqrt(((((4+4))!+(4)!)/(4)!))
42 233 44,4-,4v+ 44-4+sqrt(4)
43 75 44,4,4/- 44-4/4
44 1120 44,44*v sqrt((44*44))
45 244 44,4,4/+ 44+4/4
46 677 44,4+,4v- 44+4-sqrt(4)
47 511 4!,4,4/-,4!+ (4)!-4/4+(4)!
48 15553 44,4,4*v+ 44+sqrt((4*4))
49 834 4,4/,4!+,4!+ 4/4+(4)!+(4)!
50 1130 44,4+,4v+ 44+4+sqrt(4)
51 23 4!,4!,4,9//,4v/+ (4)!+((4)!/(.4.))/sqrt(4)
52 1001 44,4+,4+ 44+4+4
53 88 4,4,9//,44+ 4/(.4.)+44
54 2162 4,4v+,4^,4!/ (4+sqrt(4))^4/(4)!
55 87 4!,4,9//,4,4/+ (4)!/(.4.)+4/4
56 552 44,4!,4v/+ 44+(4)!/sqrt(4)
57 20 4!,4,4,9//+,4!+ (4)!+4/(.4.)+(4)!
58 90 4,4^,4!-,4/ (4^4-(4)!)/4
59 4 4,4!+,4,9//,4- (4+(4)!)/(.4.)-4
60 722 44,4,4*+ 44+4*4
61 3 4,4!+,4,9//,4v- (4+(4)!)/(.4.)-sqrt(4)
62 73 4,4*,4*,4v- 4*4*4-sqrt(4)
63 35 4,4^,4-,4/ (4^4-4)/4
64 4158 44,4-,4!+ 44-4+(4)!
65 4 4,4,4^+,4/ (4+4^4)/4
66 137 44,4!+,4v- 44+(4)!-sqrt(4)
67 2 4,4!+,4,9//,4+ (4+(4)!)/(.4.)+4
68 214 44,4,4*v!+ 44+(sqrt((4*4)))!
69 1 4!,4-,4,9//,4!+ ((4)!-4)/(.4.)+(4)!
70 101 44,4!+,4v+ 44+(4)!+sqrt(4)
71 0
72 2398 44,4+,4!+ 44+4+(4)!
73 0
74 90 4,4!*,4!-,4v+ 4*(4)!-(4)!+sqrt(4)
75 1 44,4,9//,4!- 44/(.4.)-(4)!
76 99 4,4!,4-*,4- 4*((4)!-4)-4
77 9 4,4,9//,4^v,4- sqrt((4/(.4.))^4)-4
78 96 4,4!,4-*,4v- 4*((4)!-4)-sqrt(4)
79 9 4,4,9//,4^v,4v- sqrt((4/(.4.))^4)-sqrt(4)
80 322 44,4-,4v* (44-4)*sqrt(4)
81 818 4,4/,4-,4^ (4/4-4)^4
82 19 4,4!,4-*,4v+ 4*((4)!-4)+sqrt(4)
83 12 4v,4,4,9//,4^v+ sqrt(4)+sqrt((4/(.4.))^4)
84 55 44,4v*,4- 44*sqrt(4)-4
85 12 4,4,4,9//,4^v+ 4+sqrt((4/(.4.))^4)
86 4 44,4v*,4v- 44*sqrt(4)-sqrt(4)
87 2 4,4!+,4,9//,4!+ (4+(4)!)/(.4.)+(4)!
88 345 44,44+ 44+44
89 0
90 60 44,4v*,4v+ 44*sqrt(4)+sqrt(4)
91 0
92 357 44,4v*,4+ 44*sqrt(4)+4
93 0
94 147 4,4!*,4-,4v+ 4*(4)!-4+sqrt(4)
95 145 44,4,9//,4- 44/(.4.)-4
96 9398 44,4+,4v* (44+4)*sqrt(4)
97 289 4,4/,4,4!*+ 4/4+4*(4)!
98 271 4,4,4!*+,4v- 4+4*(4)!-sqrt(4)
99 22 44,4,9//,4^vv sqrt(sqrt((44/(.4.))^4))
100 740 4,4/,4!+,4* (4/4+(4)!)*4
101 1 44,4,9//,4v+ 44/(.4.)+sqrt(4)
102 50 4,4,4!*+,4v+ 4+4*(4)!+sqrt(4)
103 1 44,4,9//,4+ 44/(.4.)+4
104 308 4,4+,4,4!*+ 4+4+4*(4)!
105 16 4,4,9//,4,4!*+ 4/(.4.)+4*(4)!
106 20 4,4!,4v+*,4v+ 4*((4)!+sqrt(4))+sqrt(4)
107 0
108 518 4,4,4!+*,4- 4*(4+(4)!)-4
109 0
110 25 4,4,4!+*,4v- 4*(4+(4)!)-sqrt(4)
111 5 444,4/ 444/4
112 349 44,4v*,4!+ 44*sqrt(4)+(4)!
DefDbl A-Z
Dim crlf$, stack(10), concatable(5), fact(15), dfact(-1 To 25), solCt(112), shortest(112) As String
Dim stackPtr, wh, pz As String, expstr As String, lvl, subfact As Variant
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
pz0 = "4444"
f = 1: fact(0) = f
For i = 1 To 15
f = f * i
fact(i) = f
Text1.Text = Text1.Text & f & crlf
Next
dfact(-1) = 1: dfact(0) = 1
For i = 1 To 25
f = 1
If i Mod 2 = 1 Then
For j = 1 To i Step 2: f = f * j: Next
Else
For j = 2 To i Step 2: f = f * j: Next
End If
dfact(i) = f
Text1.Text = Text1.Text & i & Str(f) & crlf
Next
subfact = Array(1, 0, 1, 2, 9, 44, 265, 1854, 14833, 133496)
pz = pz0
Text1.Text = Text1.Text & pz & crlf
h$ = pz
' Do
stackPtr = 1
stack(1) = Val(Left(pz, 1)): concatable(1) = 1
expstr = LTrim(Str(stack(1)))
wh = 2
addOn
permute pz
' Loop Until pz = h
For i = 1 To 112
Text1.Text = Text1.Text & i & " " & solCt(i) & " " & shortest(i) & crlf
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sub addOn()
ReDim sstack(5)
ReDim sconcatable(5)
DoEvents
For typ = 0 To 10
If typ <> 9 Then
sstackPtr = stackPtr
sexpstr$ = expstr
For i = 1 To stackPtr
sstack(i) = stack(i)
sconcatable(i) = concatable(i)
swh = wh
Next
good = 1
Select Case typ
Case 0 ' concatenate
If concatable(stackPtr) And wh < 5 Then
stack(stackPtr) = 10 * stack(stackPtr) + Val(Mid(pz, wh, 1))
expstr = expstr + Mid(pz, wh, 1)
If expstr = "44,44" Then
xx = xx
End If
wh = wh + 1
Else
good = 0
End If
Case 1 ' add (+)
If stackPtr > 1 Then
stackPtr = stackPtr - 1
stack(stackPtr) = stack(stackPtr) + stack(stackPtr + 1)
expstr = expstr + "+"
concatable(stackPtr) = 0
Else
good = 0
End If
Case 2 ' subtract (-)
If stackPtr > 1 Then
stackPtr = stackPtr - 1
stack(stackPtr) = stack(stackPtr) - stack(stackPtr + 1)
expstr = expstr + "-"
concatable(stackPtr) = 0
Else
good = 0
End If
Case 3 ' multiply (*)
If stackPtr > 1 Then
stackPtr = stackPtr - 1
stack(stackPtr) = stack(stackPtr) * stack(stackPtr + 1)
expstr = expstr + "*"
concatable(stackPtr) = 0
Else
good = 0
End If
Case 4 ' divide (/)
If stackPtr > 1 And stack(stackPtr) <> 0 Then
stackPtr = stackPtr - 1
stack(stackPtr) = stack(stackPtr) / stack(stackPtr + 1)
expstr = expstr + "/"
concatable(stackPtr) = 0
Else
good = 0
End If
Case 5 ' comma
If wh < 5 Then
stackPtr = stackPtr + 1
stack(stackPtr) = Val(Mid(pz, wh, 1))
concatable(stackPtr) = 1
expstr = expstr + "," + Mid(pz, wh, 1)
wh = wh + 1
Else
good = 0
End If
Case 6 ' power (^)
If stackPtr > 1 Then
If stack(stackPtr - 1) <> 0 And stack(stackPtr - 1) < 1000 And stack(stackPtr) >= 0 And stack(stackPtr) < 10 And (stack(stackPtr - 1) > 0 Or stack(stackPtr) = Int(stack(stackPtr))) Then
stackPtr = stackPtr - 1
stack(stackPtr) = stack(stackPtr) ^ stack(stackPtr + 1)
expstr = expstr + "^"
concatable(stackPtr) = 0
Else
good = 0
End If
Else
good = 0
End If
Case 7 ' factorial
If stack(stackPtr) = Int(stack(stackPtr)) And stack(stackPtr) <= 15 And stack(stackPtr) >= 0 And stack(stackPtr) <> 1 And stack(stackPtr) <> 2 Then
stack(stackPtr) = fact(stack(stackPtr))
expstr = expstr + "!"
concatable(stackPtr) = 0
Else
good = 0
End If
Case 8 ' radical
If stack(stackPtr) >= 0 And Right(expstr, 2) <> "vv" Then
stack(stackPtr) = Sqr(stack(stackPtr))
expstr = expstr + "v"
concatable(stackPtr) = 0
Else
good = 0
End If
Case 9 ' double factorial
If stack(stackPtr) = Int(stack(stackPtr)) And stack(stackPtr) <= 25 And stack(stackPtr) >= 4 Then
stack(stackPtr) = dfact(stack(stackPtr))
expstr = expstr + "(!!)"
concatable(stackPtr) = 0
Else
good = 0
End If
Case 10 ' 4/9
If wh < 4 Then
stackPtr = stackPtr + 1
stack(stackPtr) = 4 / 9
concatable(stackPtr) = 0
expstr = expstr + ",4,9/"
wh = wh + 1
Else
good = 0
End If
Case 11 ' subfactorial
If stack(stackPtr) = Int(stack(stackPtr)) And stack(stackPtr) <= 9 And stack(stackPtr) >= 4 Then
stack(stackPtr) = subfact(stack(stackPtr))
expstr = expstr + "s"
concatable(stackPtr) = 0
Else
good = 0
End If
End Select
If good Then
If stackPtr = 1 And wh = 5 Then
If stack(stackPtr) <= 112 And stack(stackPtr) > 0 And Abs(stack(stackPtr) - Int(stack(stackPtr) + 0.5)) < 0.000000001 Then
solCt(stack(stackPtr)) = solCt(stack(stackPtr)) + 1
If Len(expstr$) < Len(shortest(stack(stackPtr))) Or Len(shortest(stack(stackPtr))) = 0 Then
' Text1.Text = Text1.Text & mform(stack(stackPtr), "##0") & " " & expstr & crlf
shortest(stack(stackPtr)) = expstr
End If
End If
End If
If Len(expstr) < 34 Then
addOn
End If
End If
wh = swh
expstr = sexpstr
stackPtr = sstackPtr
For i = 1 To stackPtr
stack(i) = sstack(i)
concatable(i) = sconcatable(i)
Next
End If ' not typ=9
Next typ
End Sub
|
Posted by Charlie
on 2018-02-14 10:35:12 |