I think my preference is more towards conciseness.
I made a stack machine with single character instructions and needed to solve a variation of this problem. I had just the digits 0 through 9. The characters '23' would be push 2 followed by push 3. To actually represent the number 23 you would use
45*3+
or something similar.
That left me with the problem of how to encode each integer in the fewest characters.
Tools at hand.
The digits 0 through 9
'P': Pi
'*': (a * b),
'/': (a / b),
'-': (a - b),
'+': (a + b),
's': sin(a),
'c': cos(a),
'q': sqrt(a),
'l': log(a),
'~': abs(a),
'#': round(a),
'$': Math.floor(a),
'C': clamp(a),
'<': min(a, b),
'>': max(a, b),
'^': pow(a, b),
'a': atan2(a, b),
'%': positiveMod(a, b),
'!': (1 - a),
'?': (a <= 0 ? 0 : 1)
'o': a xor b scaled by c; ((a*c) xor (b*c))/c
'd': duplicate the top stack entry
':': swap the top two stack entries
';': swap the top and third stack entries
I have wondered about revisiting the stack machine with a complex number stack to see what I can come up with.
(Next time I post something like this I am not going to use my phone)
> I feel like the second you allow functions you've thrown the spirit of the game.
+, - (both binary and unary), ×, ÷ are functions, as is raising to a power. Why would you allow them?
As always in this kind of things, one can disagree about what constitutes an elementary function, but I don’t think taking square roots should be disqualified in this puzzle.
That's exactly the point. What exactly, is the set of allowable functions used for the problem? I think you, and the post you reply to, are stating the same thing.
Where do you draw a line between "Functions available on a 4-function calculator" and "Functions I can make up specifically to generate a target integer"? I think you have to rigidly define this, or the game loses meaning.
It's a game, it only has meaning insofar as it is fun for the participants. So "here's a function I happen to know that gets me a number" works as long as your friends find it plausible, or amusing.
This is a good example of why you need rules on which functions are allowed. Repeated application of the successor function makes the entire exercise trivial
This is a great point. I think what you're really responding to is that it's a game without clear rules, and so part of the "game" is thinking about creative interpretations of the rules themselves and pushing the boundary of what others originally assumed the rules to be.
Granted there is creativity in this sort of game -- indeed, most "games" in life are like this -- but it's quite a different thing from winning a game with clearly defined rules like chess, or this game with the set of allowed operations specified up front.
That gets at what makes using additional functions like in the blog post a bit arbitrary: we don't have special notation for "+ 1" or "* 2", but we do for "^(1/2)" and "log_2". It's not hard to imagine a different world where "+ 1" or "^2" had special notation, and suddenly we'd be able to solve the question in even simpler ways.
It's still a fun puzzle, it's just based more on our shared notational conventions as much as the underlying math.
> I wouldn’t call the construction given by Paul Dirac trivial. Do you think it is
Yes? It's doing exactly the thing that your parent comment complains about in the gamma function, introducing additional constants (in this case, mostly 2s) that, for no particular reason, don't count.
Why would you interpret squaring as consuming a 2, but square rooting as not consuming a 2?
It’s just about having fun at the end of the day, the gamma function and square root are considered fundamental enough. But if one wants they could try to limit to different subsets of functions and prove which numbers are possible or impossible to achieve just with those.
They also say “mathematical tools” not arbitrary functions.
This was my initial thought once we got to the Gamma function.
My reasoning is (I'm pretty sure it's the same as yours), why is the gamma function allowed, but not others? I could insert arbitrary functions to make the game arbitrarily solvable.
While this hit me at the Gamma introduction, I think it leads back to the beginning: It's a poorly defined problem from the rules at the start of the article. It should instead define the set of allowable functions (or operations) explicitly. I think you could modify this to retain the intent of showing how the problem scales with knowledge level.
I think you have a point, but as others have commented "allowing functions" is not the problem, as fundamental math operations are functions. But if we limit ourselves to only functions that map (tuples of) integers to integers ((Z, Z, ...) -> Z), the spirit of the original game is retained. This disallows sqrt and log, but retains addition, subtraction and multiplication (but not division). Factorial (n!) is allowed, as is exponentiation to a non-zero power.
Wonder if someone could come up with general solution within these constraints.
I would argue that the Gamma function is more fundamental than the factorial operation. But you are still correct that if arbitrary functions were allowed, the game would degenerate to triviality.
Maybe it's just me, but writing sqrt(2+2) instead of sqrt(2*2) or sqrt(2^2) was such an odd choice. It obfuscates the reason why 2=sqrt(2+2), and unnecessarily so.
Good point and feedback, but an odd choice by the author?
It could be the phenomenon of the author's cognitive bandwidth being consumed by everything in the article, including each argument, the overall argument, the writing, the formatting, etc. etc., and with time pressures. The critic can focus at their leisure on one point, with bandwidth to spare - and so it's obvious! :)
See also: "Representing numbers using only one 4" written by a 26-year-old Donald Knuth in 1964 (https://www.jstor.org/stable/2689238 reprinted as Chapter 10 of his Selected Papers on Fun and Games) — it uses the single digit 4, and the three operations √x (square root), ⌊x⌋ (floor, i.e. greater integer not greater than), and x! (factorial), and ends with a (still unsolved) conjecture about whether every integer can be represented in this way.
The appendix (written for the book in 2011) points out an earlier (1962) 1.5-page paper π in Four 4's by J. H. Conway and M. J. T. Guy, written when they were students at Cambridge, that has a similar idea: https://archive.org/details/eureka-25/page/18/mode/1up?view=...
I found these by accident a long time ago but kept them because they do "work". Try to input one expression in the lil box in https://www.wolframalpha.com/?source=nav and they will quickly evaluate to these values; the charade goes away after you press Enter and get the (mathematically) correct answer.
Related: there as a reverse engineering/CTF challenge (which shall remain nameless to prevent you from cheating) where my solution involved injecting shellcode that adds specific number to the stack pointer. But your shellcode -- including the number(s) you add -- can only involve bytes from the ascii alphanumeric set.
So I used a SAT solver to find a combination of numbers, not using prohibited bytes, that add up to the number I really want.
I like these games, and I would say more fun when using a larger number that has more factors, for example 120. 120 is among the superior highly composite numbers:
So, the formula is really about making any integer with three 2s, but historical precedent calls the game with four 2s more interesting, so the (stronger) result is monkey-patched by replacing a 2 with sqrt(2+2).
The problem is allowing arbitrary numbers of unary operators. If you allowed ++ increment it would be trivialized even easier. Could even do all complex numbers with only 2 twos.
> Four fours is a mathematical puzzle, the goal of which is to find the simplest mathematical expression for every whole number from 0 to some maximum, using only common mathematical symbols and the digit four. No other digit is allowed. Most versions of the puzzle require that each expression have exactly four fours, but some variations require that each expression have some minimum number of fours.
I think my preference is more towards conciseness.
I made a stack machine with single character instructions and needed to solve a variation of this problem. I had just the digits 0 through 9. The characters '23' would be push 2 followed by push 3. To actually represent the number 23 you would use
That left me with the problem of how to encode each integer in the fewest characters.Tools at hand.
I have wondered about revisiting the stack machine with a complex number stack to see what I can come up with.(Next time I post something like this I am not going to use my phone)
Reminds me of https://www.hacker.org/hvm/ (2008)
The answer in general may be uncomputable.
https://en.wikipedia.org/wiki/Kolmogorov_complexity
AHH but in practice you are limited to 50 characters.
https://c50.fingswotidun.com/
Which gives you a finite problem. The VM cannot loop or define functions (yet, anyway) so it doesn't go all busy beaver on you.
I feel like the second you allow functions you've thrown the spirit of the game.
Ex, the gamma function is (n-1)! So now you're making 7 with four twos and a one. You've broken the spirit.
If I can hide numbers in a function call... It's trivially easy to always succeed.
> I feel like the second you allow functions you've thrown the spirit of the game.
+, - (both binary and unary), ×, ÷ are functions, as is raising to a power. Why would you allow them?
As always in this kind of things, one can disagree about what constitutes an elementary function, but I don’t think taking square roots should be disqualified in this puzzle.
> Ex, the gamma function is (n-1)!
And 2 is just S(S(0)) (https://en.wikipedia.org/wiki/Peano_axioms)
> If I can hide numbers in a function call... It's trivially easy to always succeed.
I wouldn’t call the construction given by Paul Dirac trivial. Do you think it is, or do you know of a simpler one?
That's exactly the point. What exactly, is the set of allowable functions used for the problem? I think you, and the post you reply to, are stating the same thing.
Where do you draw a line between "Functions available on a 4-function calculator" and "Functions I can make up specifically to generate a target integer"? I think you have to rigidly define this, or the game loses meaning.
It's a game, it only has meaning insofar as it is fun for the participants. So "here's a function I happen to know that gets me a number" works as long as your friends find it plausible, or amusing.
> And 2 is just S(S(0))
This is a good example of why you need rules on which functions are allowed. Repeated application of the successor function makes the entire exercise trivial
This is a great point. I think what you're really responding to is that it's a game without clear rules, and so part of the "game" is thinking about creative interpretations of the rules themselves and pushing the boundary of what others originally assumed the rules to be.
Granted there is creativity in this sort of game -- indeed, most "games" in life are like this -- but it's quite a different thing from winning a game with clearly defined rules like chess, or this game with the set of allowed operations specified up front.
It sounds like you've just found one for >=2: 2, S(2), S(S(2)), ...
That, somewhat ironically, typically isn’t included in the set of elementary functions. ‘plus’ is, but ‘plus one’ isn’t.
That gets at what makes using additional functions like in the blog post a bit arbitrary: we don't have special notation for "+ 1" or "* 2", but we do for "^(1/2)" and "log_2". It's not hard to imagine a different world where "+ 1" or "^2" had special notation, and suddenly we'd be able to solve the question in even simpler ways.
It's still a fun puzzle, it's just based more on our shared notational conventions as much as the underlying math.
For example it would not be weird to have ++ instead of +1.
That’s just S(n)
Maybe they meant symbolic operators feel alright but named functions feel like cheating, so 2+2+2+⌊√2⌋ is fine but 2+2+2+floor(sqrt(2)) is not.
> I wouldn’t call the construction given by Paul Dirac trivial. Do you think it is
Yes? It's doing exactly the thing that your parent comment complains about in the gamma function, introducing additional constants (in this case, mostly 2s) that, for no particular reason, don't count.
Why would you interpret squaring as consuming a 2, but square rooting as not consuming a 2?
Because of our standard notation for those
You are inferring that as a rule of the game by making assumptions. There are other conclusions different people could reach.
you shouldn't be able to use letters. You're supposed to use four 2s and symbols, not four 2s plus the letters "l", "o", "g".
It’s just about having fun at the end of the day, the gamma function and square root are considered fundamental enough. But if one wants they could try to limit to different subsets of functions and prove which numbers are possible or impossible to achieve just with those.
They also say “mathematical tools” not arbitrary functions.
This was my initial thought once we got to the Gamma function.
My reasoning is (I'm pretty sure it's the same as yours), why is the gamma function allowed, but not others? I could insert arbitrary functions to make the game arbitrarily solvable.
While this hit me at the Gamma introduction, I think it leads back to the beginning: It's a poorly defined problem from the rules at the start of the article. It should instead define the set of allowable functions (or operations) explicitly. I think you could modify this to retain the intent of showing how the problem scales with knowledge level.
I think you have a point, but as others have commented "allowing functions" is not the problem, as fundamental math operations are functions. But if we limit ourselves to only functions that map (tuples of) integers to integers ((Z, Z, ...) -> Z), the spirit of the original game is retained. This disallows sqrt and log, but retains addition, subtraction and multiplication (but not division). Factorial (n!) is allowed, as is exponentiation to a non-zero power.
Wonder if someone could come up with general solution within these constraints.
The Dirac solution doesn’t involve gamma, just N square roots and 2 logarithms.
I would argue that the Gamma function is more fundamental than the factorial operation. But you are still correct that if arbitrary functions were allowed, the game would degenerate to triviality.
That's just what it evaluates to on integers. The standard definition of it also includes e and an integral from 0 to ∞.
Inorite. If we're allowing any old function, then I can just define 12345 as
> If I can hide numbers in a function call
Yeah this feels like those "Implemented XYZ in 1 line"
> use any mathematical operations
Okay, then this is easy, just use the successor function.
Etc.lambda calculus has entered the chat
https://wiki.haskell.org/Peano_numbers
Maybe it's just me, but writing sqrt(2+2) instead of sqrt(2*2) or sqrt(2^2) was such an odd choice. It obfuscates the reason why 2=sqrt(2+2), and unnecessarily so.
Good point and feedback, but an odd choice by the author?
It could be the phenomenon of the author's cognitive bandwidth being consumed by everything in the article, including each argument, the overall argument, the writing, the formatting, etc. etc., and with time pressures. The critic can focus at their leisure on one point, with bandwidth to spare - and so it's obvious! :)
I agree it potentially wasn't a conscious choice, but it's still interesting nonetheless.
I wasn't criticizing him for this, but rather fascinated that this is the variant that was chosen.
Speaking of odd choices:
12 = 2 * (2+2+2)
Is a hell or a lot simpler than using complex numbers. Might be a different example for that would have been better.
Maybe there's a "golf score" somewhere that rewards less expensive operations. The "Dirac hack" would run up a lot of points.
See also: "Representing numbers using only one 4" written by a 26-year-old Donald Knuth in 1964 (https://www.jstor.org/stable/2689238 reprinted as Chapter 10 of his Selected Papers on Fun and Games) — it uses the single digit 4, and the three operations √x (square root), ⌊x⌋ (floor, i.e. greater integer not greater than), and x! (factorial), and ends with a (still unsolved) conjecture about whether every integer can be represented in this way.
The appendix (written for the book in 2011) points out an earlier (1962) 1.5-page paper π in Four 4's by J. H. Conway and M. J. T. Guy, written when they were students at Cambridge, that has a similar idea: https://archive.org/details/eureka-25/page/18/mode/1up?view=...
For example,
because 24! lies between 5^{32} and 6^{32}.> There's just one small wrinkle: it uses three instances of the digit 2, not four.
One small wrinkle, if you ignore the fact that the root notation conceals exponentiation by 1/2, by making that common value a default.
That's a lot of hidden 2's!
Here are some values that are (understandably) not listed on the blog. They happen only due to the limited precision of floating point formats.
I found these by accident a long time ago but kept them because they do "work". Try to input one expression in the lil box in https://www.wolframalpha.com/?source=nav and they will quickly evaluate to these values; the charade goes away after you press Enter and get the (mathematically) correct answer.My old solvers from what feels like a previous life: https://madflame991.blogspot.com/2013/02/four-fours.html https://madflame991.blogspot.com/2013/02/return-of-four-four...
That was fun
When everything is an IEEE 754 floating point number, a mathematically "linear" function can indeed be coerced into anything: http://tom7.org/grad/
This is amazing, but there are a lot of 2's hiding in those sqrt symbols
There's the classic “four fours”, which I learned as a child in the book “The Man Who Counted”.
https://en.wikipedia.org/wiki/Four_fours
https://en.wikipedia.org/wiki/The_Man_Who_Counted
Related: there as a reverse engineering/CTF challenge (which shall remain nameless to prevent you from cheating) where my solution involved injecting shellcode that adds specific number to the stack pointer. But your shellcode -- including the number(s) you add -- can only involve bytes from the ascii alphanumeric set.
So I used a SAT solver to find a combination of numbers, not using prohibited bytes, that add up to the number I really want.
https://docs.google.com/presentation/d/19K7SK1L49reoFgjEPKCF...
Related numberphile video which goes into a different variation of using all digits in ascending and descending order: https://www.youtube.com/watch?v=-ruC5A9EzzE
but in this case there is a unsolved gap!
I like these games, and I would say more fun when using a larger number that has more factors, for example 120. 120 is among the superior highly composite numbers:
https://en.wikipedia.org/wiki/Superior_highly_composite_numb...
So, the formula is really about making any integer with three 2s, but historical precedent calls the game with four 2s more interesting, so the (stronger) result is monkey-patched by replacing a 2 with sqrt(2+2).
Why not use 3 2’s to make n + 2 or n - 2? That’s a lot easier than making a subscript so complicated.
This is the Curse of Knowledge. OP stared too long into the abyss.
You don't need the gamma function to get to 7. You can stay at an Algebra 1 level.
I solved the puzzle for 1-10 before looking at the answers, and this was my solution for 7:
⌊√222⌋/2
or more readably:
floor(sqrt(222)) / 2
If floor a legitimate mathematical function?
Yes. https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Legitimate? What do you mean?
n = (2+2)/(2+2) + ...n...
With just four instances of 2.
I kinda feel that's cheating and each square root requires a two to use it.
The problem is allowing arbitrary numbers of unary operators. If you allowed ++ increment it would be trivialized even easier. Could even do all complex numbers with only 2 twos.
Am I missing something or 7 is simply 2 + 2 + 2 + 2/2?
All those are allowed, so what's the problem?
Your first example uses 2 five times. Your second results in 3
You now have five 2s!
Ooohhh! With only 4x 2s. I get it now! I feel dummy
Wouldn't that be five 2s, not 4?
Thanks! That explains it!
i thought the famous puzzle was 4, 4s
> I've read about this story in Graham Farmelo's book The Strangest Man: The Hidden Life of Paul Dirac, Quantum Genius.
"The Strangest Man": https://en.wikipedia.org/wiki/The_Strangest_Man
Four Fours: https://en.wikipedia.org/wiki/Four_fours :
> Four fours is a mathematical puzzle, the goal of which is to find the simplest mathematical expression for every whole number from 0 to some maximum, using only common mathematical symbols and the digit four. No other digit is allowed. Most versions of the puzzle require that each expression have exactly four fours, but some variations require that each expression have some minimum number of fours.
"Golden ratio base is a non-integer positional numeral system" (2023) https://news.ycombinator.com/item?id=37969716 :
> What about radix epi*i, or just e?"
Is using a primorial permitted?
https://en.wikipedia.org/wiki/Primorial2/2+2/2…
Then you just add it multiple times
And if 0 is an integer.
2/2-2/2
Doesn’t seem like the author is recursively building solutions, so this doesn’t work.