|
Top links
Handy utilities
Contact me
|
The Four Fours
This is a well known puzzle: express each integer from 1 to 100 using standard mathematical
operations and exactly four fours. For example, 16 = 4 + 4 + 4 + 4 (obviously
in many cases there is more than one answer).
I have written a small C# program that will save you the trouble of finding the
solutions. The idea is simply to search every possible combination of operands
(4, 4!, .4, .4bar = .4444..., etc), binary operators (+, - , *, /, ^) and precedence
arrangements. It turns out that's all you need. I had the option of
increasing the speed by stopping as soon as I had found answers for all 100 numbers,
but since the thing runs so darn fast I keep it going to the bitter end in order
to find the 'nicest' answers (eg I prefer an answer that doesn't have to resort
to using the square root of .4bar).
The C# file:
Here is the program's output:
1 = (4 + 4) / (4 + 4)
2 = (4 * 4) / (4 + 4)
3 = ( (4 + 4) + 4) / 4
4 = ( (4 - 4) * 4) + 4
5 = ( (4 * 4) + 4) / 4
6 = ( (4 + 4) / 4) + 4
7 = (4 + 4) - (4 / 4)
8 = (4 + 4) + (4 - 4)
9 = (4 + 4) + (4 / 4)
10 = (4 + 4) + (4 - sqrt(4))
11 = ( (4 + 4!) / 4) + 4
12 = (4 - (4 / 4)) * 4
13 = (4 / 4) + (4! / sqrt(4))
14 = (4 + 4) + (4 + sqrt(4))
15 = (4 * 4) - (4 / 4)
16 = (4 + 4) + (4 + 4)
17 = (4 * 4) + (4 / 4)
18 = (4 * 4) + (4 - sqrt(4))
19 = (4! - 4) - (4 / 4)
20 = ( (4 / 4) + 4) * 4
21 = (4 / 4) - (4 - 4!)
22 = (4 * 4) + (4 + sqrt(4))
23 = ( (4 * 4!) - 4) / 4
24 = (4 + 4) + (4 * 4)
25 = ( (4 / 4) + 4) ^ sqrt(4)
26 = ( (4 + 4) / 4) + 4!
27 = (4 + 4!) - (4 / 4)
28 = ( (4 + 4) * 4) - 4
29 = (4 / 4) + (4 + 4!)
30 = ( (4 + 4) * 4) - sqrt(4)
31 = ( (4 + 4!) / 4) + 4!
32 = (4 * 4) + (4 * 4)
33 = (4 + 4!) + (sqrt(4) / .4)
34 = ( (4 + 4) * 4) + sqrt(4)
35 = ( (4 * 4) - sqrt(4)) / .4
36 = ( (4 + 4) * 4) + 4
37 = (4 + 4!) + (4 / .4bar)
38 = (4 * 4) - (sqrt(4) - 4!)
39 = ( (4 * 4) - .4) / .4
40 = ( (4 * 4) + 4) * sqrt(4)
41 = ( (4 * 4) + .4) / .4
42 = (4 * 4) + (sqrt(4) + 4!)
43 = (sqrt(4) * 4!) - (sqrt(4) / .4)
44 = (4 * 4) + (4 + 4!)
45 = ( (4 * 4) + 4) / .4bar
46 = ( (4 * 4!) - 4) / sqrt(4)
47 = (sqrt(4) * 4!) - (4 / 4)
48 = ( (4 + 4) + 4) * 4
49 = (4 / 4) + (sqrt(4) * 4!)
50 = ( (4 * 4) + 4) / .4
51 = ( (4! - sqrt(4)) / .4) - 4
52 = ( (4 - sqrt(4)) * 4!) + 4
53 = (4! / .4bar) - (4 / 4)
54 = ( (4 + sqrt(4)) ^ 4) / 4!
55 = (4 / 4) + (4! / .4bar)
56 = ( (4 * 4) - sqrt(4)) * 4
57 = (4 / .4bar) + (sqrt(4) * 4!)
58 = ( (4 ^ 4) - 4!) / 4
59 = (4! / .4) - (4 / 4)
60 = ( (4 * 4) * 4) - 4
61 = (4 / 4) + (4! / .4)
62 = ( (4 * 4) * 4) - sqrt(4)
63 = ( (4 ^ 4) - 4) / 4
64 = (4 + 4) * (4 + 4)
65 = ( (4 ^ 4) + 4) / 4
66 = ( (4 * 4) * 4) + sqrt(4)
67 = ( (4 + 4!) / .4bar) + 4
68 = ( (4 * 4) * 4) + 4
69 = ( (sqrt(4) + 4!) / .4) + 4
70 = ( (4 ^ 4) + 4!) / 4
71 = ( (4 + 4!) + .4) / .4
72 = ( (4 * 4) + sqrt(4)) * 4
73 = ( (sqrt(4) * 4!) + sqrt(.4bar)) / sqrt(.4bar)
74 = (4 * 4!) + (sqrt(4) - 4!)
75 = ( (4 + sqrt(4)) + 4!) / .4
76 = ( (4! - 4) * 4) - 4
77 = ( (4 / .4bar) ^ sqrt(4)) - 4
78 = ( (4! - 4) * 4) - sqrt(4)
79 = ( (4 / .4bar) ^ sqrt(4)) - sqrt(4)
80 = ( (4 * 4) + 4) * 4
81 = ( (4 / 4) - 4) ^ 4
82 = ( (4! - 4) * 4) + sqrt(4)
83 = ( (4 / .4bar) ^ sqrt(4)) + sqrt(4)
84 = ( (4! - 4) * 4) + 4
85 = ( (4 / .4bar) ^ sqrt(4)) + 4
86 = ( (4! - sqrt(4)) * 4) - sqrt(4)
87 = (4 * 4!) - (4 / .4bar)
88 = (4 * 4!) - (4 + 4)
89 = ( (sqrt(4) + 4!) / .4) + 4!
90 = (4 * 4!) - (4 + sqrt(4))
91 = (4 * 4!) - (sqrt(4) / .4)
92 = (4! - (4 / 4)) * 4
93 = (4 * 4!) - (sqrt(4) / sqrt(.4bar))
94 = (4 * 4!) - (4 - sqrt(4))
95 = (4 * 4!) - (4 / 4)
96 = (4 * 4) * (4 + sqrt(4))
97 = (4 / 4) + (4 * 4!)
98 = (4 - sqrt(4)) + (4 * 4!)
99 = ( (sqrt(4) * 4!) - 4) / .4bar
100 = ( (4 + 4) + sqrt(4)) ^ sqrt(4)
Done. (648000 loop iterations)
Elapsed time: 358 milliseconds
|