Subscribe via feed.

## 4 + 4 + 4 + 4 =16

Posted by ragknot on June 11, 2013 – 8:51 pm

This is like another old ToM. LOL and pretty easy.

If each of the “+”’s could be either “+” or “-” or “*” or “/” then
how many different answers could there be?

And what would be the largest and the smallest answers?

This post is under “Tom” and has 14 respond so far.

### 14 Responds so far- Add one»

1. 1. jan jansen Said：

In order of magnitude (I counted 24):

-60
-16
-15
-8
-7
-3.75
-1
0
0.0625
1
2
3.75
4.25
7
8
9
15
16
17
24
32
60
68
256

2. 2. Chris Said：

I was going to say 4^3 = 64, but realised that was naive. So 64 is only the upper bound. Obviously there are less possibilities as without any effort I can see several ways to get 0. e.g. 4/4 – 4/4 and 4*4 – 4*4 etc.

3. 3. ragknot Said：

Jan!

Also there are 64 different equations, and nine of them will give zero.

4 + 4 – 4 – 4= 0
4 / 4 * 4 – 4= 0
4 / 4 – 4 / 4= 0
4 * 4 / 4 – 4= 0
4 * 4 – 4 * 4= 0
4 – 4 + 4 – 4= 0
4 – 4 / 4 * 4= 0
4 – 4 * 4 / 4= 0
4 – 4 – 4 + 4= 0

But then suppose that “(” and “)” could be used.

4. 4. ragknot Said：

Upper bound?
Well, 4 * 4 * 4 * 4= 256, like Jan showed.
The 64 different ways gave me…

```---, *--, -*-, --*, **-, *-*, -**, ***, **/, **+, */-, *-/,
-*/, */*, *//, */+, *+-, *-+, -*+, *+*, *+/, *++, /--, -/-,
--/, /*-, /-*, -/*, /**, /*/, /*+, //-, /-/, -//, //*, ///,
//+, /+-, /-+, -/+, /+*, /+/, /++, +--, -+-, --+, +*-, +-*,
-+*, +**, +*/, +*+, +/-, +-/, -+/, +/*, +//, +/+, ++-, +-+,
-++, ++*, ++/, +++
```
5. 5. ragknot Said：

What? This screen does something weird. The first I enter was 3 minus’s and it looks like this. I will do it again.
Three minus’s with spaces is – - -, but without spaces it looks like “—” !

6. 6. Chris Said：

Hi ragknot. I’ve fixed it. You need to use the <pre> tag at the beginning and end it with </pre>

I’m afraid this silly nonsense is down to the daft spec of html.

7. 7. ragknot Said：

Thanks Chris! I just saw it was repaired.

8. 8. Chris Said：

Me too, 24 it is.

9. 9. DP Said：
```-	*	*	(-60)
-	-	*	(-16)
-	*	-	(-16)
/	-	*	(-15)
+	-	*	(-8)
-	-	-	(-8)
-	*	+	(-8)
/	/	-	(-3.75)
-	-	/	(-1)
-	/	-	(-1)
+	-	-	(0)
-	+	-	(0)
-	-	+	(0)
-	*	/	(0)
-	/	*	(0)
*	-	*	(0)
*	/	-	(0)
/	-	/	(0)
/	*	-	(0)
/	/	/	(0.0625)
+	/	-	(1)
-	+	/	(1)
*	/	/	(1)
/	+	-	(1)
/	-	+	(1)
/	*	/	(1)
/	/	*	(1)
/	+	/	(2)
-	/	/	(3.75)
+	/	/	(4.25)
/	/	+	(4.25)
+	-	/	(7)
-	/	+	(7)
+	+	-	(8)
+	-	+	(8)
+	*	/	(8)
+	/	*	(8)
-	+	+	(8)
*	-	-	(8)
*	/	+	(8)
/	*	+	(8)
+	+	/	(9)
+	/	+	(9)
/	+	+	(9)
*	-	/	(15)
+	+	+	(16)
+	*	-	(16)
-	+	*	(16)
*	+	-	(16)
*	-	+	(16)
*	*	/	(16)
*	/	*	(16)
/	*	*	(16)
*	+	/	(17)
/	+	*	(17)
+	+	*	(24)
+	*	+	(24)
*	+	+	(24)
*	+	*	(32)
*	*	-	(60)
+	*	*	(68)
*	*	+	(68)
*	*	*	(256)
```
10. 10. Chris Said：

By upper bound I mean the maximum number of possible different results.

—–
Now what if add “^” (exponentiation) to the list of operators!!!!!

—–
Minor VBA tip. You can evaluate a mathematical expression thusly:

result = Evaluate(“4*4+4-4″)

result will contain 16 as a numeric type.

11. 11. jan jansen Said：

If I add “^” I get 51 unique answers. Pretty obvious what the biggest and smallest answer is.

12. 12. ragknot Said：

Wow DP, you did it just like I did.

13. 13. Chris Said：

I’m guessing that we’re all using computers for this one. I did. My code is very quick and dirty. This one is for the 5 operator version. I’ve gone a bit OTT on one aspect – I needn’t have bothered with the maffs type or saving the evaluation strings.

I get 51 unique values too.

```Option Explicit
'To load this into Excel: open Excel, click on a cell, press ALT+F11.
'The VBA window should open. On the menu click "Insert", then "Module".
'Paste this code into the "Module1" code window. Add the Debug tool bar.

Type maffs
s As String
v As Double
End Type

Dim ma(0 To 124) As maffs

Sub Main()
' eval 4?4?4?4, where ? is * / + - or ^
Dim n As Integer, i As Integer, j As Integer, k As Integer
Dim s As String
Dim v As Double, c As Integer, u As Integer
Dim op(0 To 4) As String * 1

op(0) = "+": op(1) = "-": op(2) = "*": op(3) = "/": op(4) = "^"

For n = 0 To 124
i = (n Mod 5)
j = ((n \ 5) Mod 5)
k = ((n \ 25) Mod 5)

ma(n).s = "4" + op(k) + "4" + op(j) + "4" + op(i) + "4"
ma(n).v = Evaluate(ma(n).s)

'Debug.Print ma(n).s; " = "; ma(n).v
Next n
BubbleSort

'prepare for counting
v = ma(0).v  'old value
c = 1        'count #times detected
u = 1        ' #unique values
For i = 1 To 124 'do the stats
If ma(i).v = v Then
c = c + 1
Else
Debug.Print c; "occurrences of "; v
c = 1
u = u + 1
v = ma(i).v
End If
Next i
Debug.Print c; "occurrences of "; v
Debug.Print u; " unique values"; vbCrLf

End Sub

Sub BubbleSort()
'a really crude sorting algorithm. sorts global ma()
Dim i As Integer, swapped As Boolean
Dim s As String, v As Double

Do
swapped = False
For i = 0 To 123
If ma(i).v > ma(i + 1).v Then
s = ma(i).s
v = ma(i).v
ma(i).s = ma(i + 1).s
ma(i).v = ma(i + 1).v
ma(i + 1).s = s
ma(i + 1).v = v
swapped = True
End If
Next i
Loop Until Not swapped
End Sub
```
14. 14. DP Said：

I actually just did it in excel the brute-force way following a pattern (+,-,*,/) …

+++
++-
++*
++/
+-+
+–
+-*
+-/
……

then sorted by value.

PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\ext\php_mssql.dll' - The specified module could not be found. in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\ext\php_pdo_mssql.dll' - The specified module could not be found. in Unknown on line 0