All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Three fours (Posted on 2017-12-06)
Majority of the integers from 1 to 100 can be evaluated using three 4's, +, -, *, /, ^, sqrt, decimal point, dot above a number, and !,!!,...? (both as factorials, multifactorials and subfactorials).

Clearly, both concatenation and brackets are allowed.

Let's try to minimize the set of "not achievable" numbers.

Team work to include all possible answers is encouraged.

 No Solution Yet Submitted by Ady TZIDON No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solutions (spoilers) | Comment 1 of 3
The following list assumes exactly three 4's are needed.

The subfactorial was used only if no other way resulted in a given  number.  Other than that, the way of achieving a given number that had the shortest RPN representation is used. In most instances that is the one with the fewest operations, but those that used 4 and 44, rather than three separate 4's, had a slightly better chance, with only one comma instead of two. Those that used double-factorial (!!) were penalized by taking up 4 bytes for this one operation rather than one.

On the RPN side v represents square root and s represents subfactorial; both are postfixed, just like factorial itself, in RPN. As mentioned, double factorial is represented in both RPN and algebraic notation as (!!), while !! would represent the factorial of a factorial. The notation .4. represents .4 with a dot over the 4 to represent repetition; it's listed on the RPN side as ,4,9/

RPN                         Algebraic

1  4,4/,4^                     (4/4)^4
2  4,4+,4/                     (4+4)/4
3  4,4,4/-                     4-4/4
4  4,4+,4-                     4+4-4
5  4,4/,4+                     4/4+4
6  4,4+,4v-                    4+4-sqrt(4)
7  4,4!+,4/                    (4+(4)!)/4
8  4,4*,4*v                    sqrt((4*4*4))
9  4,4/,4(!!)+                 4/4+(4)(!!)
10  4,4+,4v+                    4+4+sqrt(4)
11  44,4/                       44/4
12  4,4+,4+                     4+4+4
13  4!,4v+,4v/                  ((4)!+sqrt(4))/sqrt(4)
14  4,4*,4v-                    4*4-sqrt(4)
15  4,4/,4+(!!)                 ((4/4+4))(!!)
16  4,4+,4v*                    (4+4)*sqrt(4)
17  4!,4(!!)(!!)+,4!/           ((4)!+((4)(!!))(!!))/(4)!
18  4,4*,4v+                    4*4+sqrt(4)
19  4(!!),4,9/+,4,9//           (4(!!)+.4.)/(.4.)
20  44,4!-                      44-(4)!
21  4!,4!,4(!!)/-               (4)!-(4)!/(4)(!!)
22  44,4v/                      44/sqrt(4)
23  4!,4,4/-                    (4)!-4/4
24  4,4+,4-!                    ((4+4-4))!
25  4,4/,4!+                    4/4+(4)!
26  4,4!+,4v-                   4+(4)!-sqrt(4)
27  4!,4!,4(!!)/+               (4)!+(4)!/(4)(!!)
28  4,4*v,4!+                   sqrt((4*4))+(4)!
29  4!,4-,4s+                   4!-4+!4
30  4,4!+,4v+                   4+(4)!+sqrt(4)
31  4,4!+,4sv+                  4+4!+sqrt(!4)
32  4,4+,4*                     (4+4)*4
33  4!,4,4,9//+                 (4)!+4/(.4.)
34  4,4(!!)*,4v+                4*(4)(!!)+sqrt(4)
35  4!,4,9/v-,4,9/v/            ((4)!-sqrt((.4.)))/sqrt((.4.))
36  44,4(!!)-                   44-(4)(!!)
37  4,4!+,4s+                   4+4!+!4
38  4!,4,9/v/,4v+               (4)!/sqrt((.4.))+sqrt(4)
39  4!,4v+,4,9/v/               ((4)!+sqrt(4))/sqrt((.4.))
40  44,4-                       44-4
41  4!,4(!!)!+,4!/v             sqrt((((4)!+((4)(!!))!)/(4)!))
42  44,4v-                      44-sqrt(4)
43  4,4s-,4sv!(!!)+             4-!4+(sqrt(!4))!(!!)
44  44,4^vv                     sqrt(sqrt(44^4))
45  4(!!)(!!),4!-,4(!!)/        (((4)(!!))(!!)-(4)!)/(4)(!!)
46  44,4v+                      44+sqrt(4)
47  4(!!)(!!),4(!!)-,4(!!)/     (((4)(!!))(!!)-(4)(!!))/(4)(!!)
48  44,4+                       44+4
49  4(!!),4(!!)(!!)+,4(!!)/     ((4)(!!)+((4)(!!))(!!))/(4)(!!)
50  4!,4!+,4v+                  (4)!+(4)!+sqrt(4)
51  4!,4(!!)(!!)+,4(!!)/        ((4)!+((4)(!!))(!!))/(4)(!!)
52  44,4(!!)+                   44+(4)(!!) 53 44,4s+ 44+!4
54  4,4*v!,4,9//                (sqrt((4*4)))!/(.4.)
55  4!,4,9/+,4,9//              ((4)!+.4.)/(.4.)
56  4,4!+,4v*                   (4+(4)!)*sqrt(4)
57  4!,4!+,4s+                  4!+4!+!4
58  4,4!,4,9//+                 4+(4)!/(.4.)
59  4v,4s+,4sv!(!!)+            sqrt(4)+!4+(sqrt(!4))!(!!)
60  4(!!),4^v,4-                sqrt((4)(!!)^4)-4
61  4,4sv^,4sv-                 4^(sqrt(!4))-sqrt(!4)
62  4(!!),4^v,4v-               sqrt((4)(!!)^4)-sqrt(4)
63  4,4!+,4,9//                 (4+(4)!)/(.4.)
64  4,4*,4*                     4*4*4
65  4(!!)!,4sv!!/,4s+           (4(!!)!)/(sqrt(!4)!)! + !4
66  4v,4(!!),4^v+               sqrt(4)+sqrt((4)(!!)^4)
67  4,4sv^,4sv+                 4^(sqrt(!4))+sqrt(!4)
68  44,4!+                      44+(4)!
69  4!,4sv*,4sv-                4!*sqrt(!4)-sqrt(!4)
70  4(!!)!,4!/,4!/              (((4)(!!))!/(4)!)/(4)!
71  4(!!),4(!!)!+,4(!!)/v       sqrt((((4)(!!)+((4)(!!))!)/(4)(!!)))
72  4,4!*,4!-                   4*(4)!-(4)!
73  4,4sv^,4s+                  4!^sqrt(!4)+!4
74  4!,4sv*,4v+                 4!*sqrt(!4)+sqrt(4)
75  4!,4sv*,4sv+                4!*sqrt(!4)+sqrt(!4)
76  4,4!,4sv*+                  4+4!*sqrt(!4)
77  4s,4^v,4-                   sqrt((!4)^4)-4
78  4!,4!,4,9//+                (4)!+(4)!/(.4.)
79  4s,4^v,4v-                  sqrt((!4)^4)-sqrt(4)
80  4,4!,4-*                    4*((4)!-4)
81  4!,4(!!)/,4^                ((4)!/(4)(!!))^4
82  4v,4sv!!,4s/+               sqrt(4)+(sqrt(!4)!)!/!4
83  4v,4s,4^v+                  sqrt(4)+sqrt(!4^4)
84  4,4!+,4sv*                  (4+4!)*sqrt(!4)
85  4,4s,4^v+                   4+sqrt(!4^4)
86  4sv!,4sv!!,4s/+             (sqrt(!4))!+(sqrt(!4)!)!/!4
87  4,4!*,4s-                   4*4!-!4
88  44,4v*                      44*sqrt(4)
89  4(!!),4s,4^v+               4(!!)+(!4)^sqrt(4)
90  4,4v+!,4(!!)/               ((4+sqrt(4)))!/(4)(!!)
91  4(!!),4sv!s+,4sv/           (4(!!)+!(sqrt(!4)!))/sqrt(!4)
92  4,4!*,4-                    4*4!-4
93  4,4!*,4sv-                  4*4!-sqrt(!4)
94  4,4!*,4v-                   4*4!-sqrt(4)
95  4(!!)(!!),4-,4/             (4(!!)(!!)-4)/4
96  4,4*v,4!*                   sqrt(4*4)*4!
97  4,4(!!)(!!)+,4/             (4+4(!!)(!!))/4
98  4,4!*,4v+                   4*4!+sqrt(4)
99  44,4,9//                    44/.4.
100  4,4,4!*+                   4+4*4!

Actually, we can go to 132 before getting to an impossible 133 (but the only multifactorial tried continues to be double factorial, no higher) :

101  4,4sv+(!!),4-              (4+sqrt(!4))(!!)-4
102  4,4!*,4sv!+                4*4!+sqrt(!4)!
103  4,4sv+(!!),4v-             (4+sqrt(!4))(!!)-sqrt(4)
104  4,4!,4v+*                  4*(4!+sqrt(4))
105  4,4!*,4s+                  4*4!+!4
106  4s,4s(!!)+,4s/             (!4+(!4)(!!))/!4
107  4,4sv+(!!),4v+             (4+sqrt(!4))(!!)+sqrt(4)
108  4,4!,4sv+*                 4*(4!+sqrt(!4))
109  4,4,4sv+(!!)+              4+(4+sqrt(!4))(!!)
110  4v,4s+!,4s!/               (sqrt(4)+!4)!/(!4)!
111  4s,4-!,4s-                 (!4-4)!-!4
112  4,4,4!+*                   4*(4+4!)
113  4,4sv+(!!),4(!!)+          (4+sqrt(!4))(!!)+4(!!)
114  4s,4-!,4sv!-               (!4-4)!-sqrt(!4)!
115  4,4sv!s*,4s(!!)-           4*!(sqrt(!4)!)-(!4)(!!)
116  4s,4-!,4-                  (!4-4)!-4
117  4,4s+,4s*                  (4+!4)*!4
118  4s,4-!,4v-                 (!4-4)!-sqrt(4)
119  4,4+(!!),4sv!s-            (4+4)(!!)-!(sqrt(!4)!)
120  4,4/,4+!                   (4/4+4)!
121  4v,4s+,4^v                 sqrt((sqrt(4)+!4)^4)
122  4v,4s,4-!+                 sqrt(4)+(!4-4)!
123  4s,4-!,4sv+                (!4-4)!+sqrt(!4)
124  4,4s,4-!+                  4+(!4-4)!
125  4s,4-,4sv^                 (!4-4)^sqrt(!4)
126  4s,4-!,4sv!+               (!4-4)!+(sqrt(!4))!
127  4(!!)s,4sv!,4^+v           sqrt(!(4(!!))+(sqrt(!4))!^4)
128  4,4^,4v/                   4^4/sqrt(4)
129  4s,4-!,4s+                 (!4-4)!+!4
130  4v,4(!!)(!!),4sv/+         sqrt(4)+(4(!!))(!!)/sqrt(!4)
131  4sv!s,4sv-,4v/             (!(sqrt(!4)!)-sqrt(!4))/sqrt(4)
132  44,4sv*                    44*sqrt(!4)
133
134  4sv,4sv!s+,4v/
135  4!,4s-,4s*                 I quit translating these.
136  4!,4sv!*,4(!!)-            (translation program didn't take care
137  4s,4sv!s+,4v/                of subfactorial; I could have added
138  4!,4sv!*,4sv!-               that feature, but foolishly did
139                                manual conversions)
140  4!,4sv!*,4-
141  4!,4sv!*,4sv-
142  4!,4sv!*,4v-
143  4,4s+(!!),4s(!!)/
144  4,4*,4s*
145  4sv!s,4s,4-!-
146  4!,4sv!*,4v+
147  4!,4sv!*,4sv+
148  4,4!,4sv!*+
149

The program is based on one for a preceding puzzle involving permutations of the digits 3, 1 and 4. The reference to permute, and the enclosing loop are commented out as now all three digits are 4.

DefDbl A-Z
Dim crlf\$, stack(10), concatable(4), fact(15), dfact(-1 To 25), solCt(100), shortest(100) As String
Dim stackPtr, wh, pz As String, expstr As String, lvl, subfact As Variant

Form1.Visible = True
Text1.Text = ""
crlf = Chr\$(13) + Chr\$(10)

pz0 = "444"

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

'   permute pz
'  Loop Until pz = h

For i = 1 To 100
Text1.Text = Text1.Text & i & "  " & shortest(i) & crlf
Next

Text1.Text = Text1.Text & crlf & " done"

End Sub

ReDim sstack(4)
ReDim sconcatable(4)

DoEvents
For typ = 0 To 11
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 < 4 Then
stack(stackPtr) = 10 * stack(stackPtr) + Val(Mid(pz, wh, 1))
expstr = expstr + Mid(pz, wh, 1)
wh = wh + 1
Else
good = 0
End If
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 < 4 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
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 = 4 Then

If stack(stackPtr) <= 100 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
End If
End If
wh = swh
expstr = sexpstr
stackPtr = sstackPtr
For i = 1 To stackPtr
stack(i) = sstack(i)
concatable(i) = sconcatable(i)
Next

Next typ

End Sub

Edited on December 6, 2017, 7:37 pm

Edited on December 7, 2017, 9:01 am
 Posted by Charlie on 2017-12-06 19:34:47

 Search: Search body:
Forums (0)