February 23rd, 2025

Making any integer with four 2s

The article explores a mathematical puzzle using four instances of the digit 2 to create any natural number through various operations, highlighting educational examples and historical contributions from mathematicians.

Read original articleLink Icon
CuriosityNostalgiaFrustration
Making any integer with four 2s

The article discusses a mathematical puzzle involving the use of exactly four instances of the digit 2 to create any target natural number through various mathematical operations. It provides examples suitable for different educational levels, starting with simple equations for elementary school students, such as using addition and division to create numbers like 1, 2, and 3. As the complexity increases, middle school students can utilize exponents and factorials to generate larger numbers, including 18 and 28. The article also highlights creative approaches to reach specific numbers, such as using the Gamma function to easily derive 7. It notes that mathematicians have historically enjoyed this puzzle, with Paul Dirac's discovery of a general solution for all numbers being a notable point in its history. The article concludes by presenting a general formula for expressing any number using nested square roots and logarithms, while ensuring the use of exactly four 2s, thus maintaining the integrity of the puzzle.

- The puzzle involves using four 2s to create any natural number.

- Simple operations can generate small numbers, while advanced math allows for larger numbers.

- The Gamma function and complex numbers can simplify reaching certain targets.

- Paul Dirac found a general solution for expressing any number with this method.

- The challenge lies in creatively using mathematical operations while adhering to the four 2s rule.

AI: What people are saying
The comments on the article about using four instances of the digit 2 to create natural numbers reveal various perspectives and insights on the mathematical puzzle.
  • Many commenters reference similar puzzles, such as the "four fours" challenge, highlighting its historical significance and variations.
  • There is a debate over the use of functions and operations, with some arguing that it complicates the spirit of the game.
  • Several users share their own methods and solutions for generating numbers, showcasing creativity in mathematical approaches.
  • Comments reflect on the educational value of such puzzles and their role in developing problem-solving skills.
  • Some users express skepticism about certain solutions, questioning whether they adhere to the original rules of the puzzle.
Link Icon 35 comments
By @horsawlarway - about 2 months
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.

By @tantalor - about 2 months
> use any mathematical operations

Okay, then this is easy, just use the successor function.

  S(n) = n+1

  6 = 2*2*2-2
  7 = S(2*2*2-2)
  8 = S(S(2*2*2-2))
Etc.
By @svat - about 2 months
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,

    5 = ⌊√√√√√(4!)!⌋
because 24! lies between 5^{32} and 6^{32}.
By @tasn - about 2 months
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.
By @Lerc - about 2 months
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)

By @kazinator - about 2 months
> 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!

By @SilasX - about 2 months
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...

By @pil0u - about 2 months
This reminds me of this mobile game Tchisla[0] where you have to build all numbers up to 1000 (10000?) using only a given digit and a couple of operators (including sqrt and !)

It was a lot of fun, you tend to develop strategies and the game has a simple, efficient UX. Fair warning, it is very time consuming.

[0] https://apps.apple.com/fr/app/tchisla-number-puzzle/id110062...

By @virgulino - about 2 months
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

By @ziofill - about 2 months
This is amazing, but there are a lot of 2's hiding in those sqrt symbols
By @madflame991 - about 2 months
Here are some values that are (understandably) not listed on the blog. They happen only due to the limited precision of floating point formats.

  128              = √(2 / √√(√2 - (2 / √2)))
  8192             = √√(2 / ((√2 * √2) - 2))
  16384            = (2 / √√(√2 - (2 / √2)))
  67108864         = √(2 / ((√2 * √2) - 2))
  134217728        = (2 / √(√2 - (2 / √2)))
  4503599627370496 = (2 / ((√2 * √2) - 2))
  9007199254740992 = (2 / (√2 - (2 / √2)))
  6369051672525773 = (√2 / (√2 - (2 / √2)))
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

By @BobbyTables2 - about 2 months
Very clever, but using an arbitrary number of square roots seems almost cheating since it’s practically another symbol for a “2” (exponent of 1/2)
By @westurner - about 2 months
> 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.

By @TZubiri - about 2 months
I think I saw this one on an ancient arab math problems book. But it may be apocryphal, not sure how many tools they would have had, factorial symbols?

At any rate they invented algebra so maybe there's something to it

Edit: It was the man who counted, definitely apocryphal, as it was written in the 20th century

By @hansonkd - about 2 months
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!

By @lblume - about 2 months
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).
By @bicepjai - about 2 months
Wow, it’s been ages since I stumbled upon a math problem that’s not only a blast to solve but also tells a tale! This one’s got it all: easy to grasp, deliciously complex, and comes with a side of drama where some genius totally threw a wrench in the works for everyone else. Bravo!
By @omoikane - about 2 months
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...

By @nubinetwork - about 2 months
I came across a similar video a couple weeks ago about how many ways you can turn a 2 into a 4... https://youtu.be/VEQOv61Gveg
By @volemo - about 2 months
I kinda feel that's cheating and each square root requires a two to use it.
By @jansan - about 2 months
Is using a primorial permitted?

    7 = (2+2)#+2/2
https://en.wikipedia.org/wiki/Primorial
By @everfree - about 2 months
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

By @crorella - about 2 months
I used to play this game when a kid but with four number 4 instead. Just operators (+,!,/,-,*, ^, etc)
By @xandrius - about 2 months
Am I missing something or 7 is simply 2 + 2 + 2 + 2/2?

All those are allowed, so what's the problem?

By @gricardo99 - about 2 months

  Getting to 7 is notoriously difficult
What am I missing?

2 * 2 * 2 - 2/2

By @unification_fan - about 2 months
This is just Peano arithmetic with extra steps
By @mbfg - about 2 months
i thought the famous puzzle was 4, 4s
By @z3t4 - about 2 months
9 = 22 / 2 - 2
By @chasingbrains - about 2 months
Is 7 really notoriously difficult to define?

7 = 2/2 + 2 + 2 + 2

By @gabrielsroka - about 2 months
By @pinoy420 - about 2 months
2/2+2/2…

Then you just add it multiple times

And if 0 is an integer.

2/2-2/2