Making any integer with four 2s (2025) (eli.thegreenplace.net)

172 points by germanrabbit 17 hours ago

hahajk 14 hours ago

i know everyone plays with their own rules, but from my perspective, a square root spends a 2 - it's not an operator like + or ! . there's an implicit "2" since you could also take the cube root or fourth root

jjmarr 11 hours ago

You can use `sin(arctan())` as the repeatable operator instead of sqrt(). Then "unwrap" by applying ^-2 - (2^-2)

3=(sin(arctan(sin(arctan(sin(arctan(2))))))^−2 − (2)^−2

shiandow 3 hours ago

There's a 2 in the definition of sin :-)

Though it really depends which definitions you find more fundamental.

Still, exp and log seem like good choices.

schiffern 5 hours ago

Perfect answer, I hate it :)

JumpCrisscross 13 hours ago

> it's not an operator like + or !

Squaring is to multiplication as is the latter to addition. If roots are invalid then so should be multiplications.

penteract 12 hours ago

Exponentiation is to multiplication as multiplication is to addition. Squaring is to multiplication as doubling is to addition.

jolmg 9 hours ago

SamBam 12 hours ago

GP didn't say roots are invalid, just that they burn a two.

If we agree that 2^2 uses two twos (and, indeed, that 2^3 isn't valid, because it uses a 3), then what's the equivalent of a square root?

Of course to my simple math brain, a square root is ^1/2, which includes the digit 1. But I agree there is someone 2-ish about the square root.

direwolf20 10 hours ago

danparsonson 13 hours ago

Would you elaborate on that? That doesn't make any sense to me

drfloyd51 12 hours ago

jibalt 11 hours ago

spieglt 12 hours ago

Biganon 3 hours ago

Yes, taking the nth root is an operator. Taking the SQUARE root is this operator with the operand 2, which is usually graphically omited. I totally agree with the top comment: it's burning one of the 2's.

ta2345fa59be 7 hours ago

Or use the successor operator.

SideQuark 13 hours ago

Alternatively, one can claim sqrt is a single symbol, and there are extensions requiring a digit. Log, ln, also have hidden bases, but they’re also valid symbols. Cos/sin may be in radians or degrees, both in common use, and no real place to denote it.

One could even claim division is raising to the -1 power, thereby disqualifying it in exactly the same manner you disqualify sqrt. I’ve never seen sqrt with a 2 index; power -1 is seen quite often for division.

Go figure….

Someone 3 hours ago

It’s true cheating, but if you assume the Peano axioms, you can write any integer with one zero without having to resort to complex functions such as √. For example (if I didn’t miscount the S-es or parentheses),

  S(S(S(S(S(S(S(0)))))))) = 7

rav 2 hours ago

You don't even need zero in that case, you can use the fact that 2 - 2 = 0 to use the four 2s:

  S(S(S(S(S(S(S(2+2-2+2)))))))) = 7
...which is essentially the same as Dirac's general solution (which also derives a "successor operator" akin to S that doesn't spend any numeric literals).

EDIT: I realize that this was already posted in a comment by shoo several hours ago.

vessenes 2 hours ago

You’ve got S(4) in the center there

adas0693 16 hours ago

there is a related problem (inspired by an interview questions from ITA software, a part of Google now) that asks to find the smallest positive integer that cannot be expressed using a digit K (in [2,9]) N times in an expression that involves the four basic arithmetic operations and the parentheses: +, -, *, /, (, and ).

to make the problem more interesting, the list of operations can be extended to include exponentiation and concatenation.

for example, using the four basic operations for N=4, and K in [2,9], we get:

7 cannot be computed in 4 2s; 11 cannot be computed in 4 3s; 10 cannot be computed in 4 4s; 8 cannot be computed in 4 5s; 9 cannot be computed in 4 6s; 4 cannot be computed in 4 7s; 5 cannot be computed in 4 8s; 4 cannot be computed in 4 9s;

catlifeonmars 14 hours ago

This feels very suspiciously like a finite field problem.

genter 16 hours ago

Are you allowed to brute force it?

argee 14 hours ago

That's how you do it right? It's a BFS with 4 being the max depth, and you print whatever numbers in the problem set which you didn't find.

twoodfin 2 hours ago

dooglius 11 hours ago

Figuring that out is presumably part of the interview (and would depend on N)

gnabgib 17 hours ago

Popular last year (368 points, 165 comments) https://news.ycombinator.com/item?id=43145753

bajard 8 hours ago

22 is cheating because 22 = 2*10+2 is arbitrary in base 10. If you write 22 in some base, you have to write the base, and that's an extra number.

teo_zero 16 hours ago

Never understood why 7 is considered difficult...

7 = ⌈ 2.2² + 2 ⌉

blueblock 15 hours ago

Rounding spoils the fun of the puzzle.

nostrademons 14 hours ago

It seems very much in the spirit of allowing concatenation and square roots...

jtari3333 7 hours ago

Rounding is a completely valid mathematical operation.

anthk 12 hours ago

(2 << 2) - ( 2 / 2)

AnimalMuppet 16 hours ago

It is difficult when the rules do not allow exponentiation.

Jtsummers 15 hours ago

  7 = ⌈ 2.2 + 2 + 2⌉
Would still work.

allywilson 7 hours ago

I'll just drop this here (yes, it's 4 instead of 2 - they're twice as good): https://fourmula.awsum.info/

Arnt 16 hours ago

Spoilsport.

And JFYI since December is near: https://rant.gulbrandsen.priv.no/hack/advent-calendar-for-ne...

shoo 8 hours ago

There's a direct trivial solution for any natural number using the successor function S(a) = a + 1 from Peano arithmetic.

Encode 0 as 2 + 2 - 2 - 2 then apply S a times to that 0.

Only depends upon natural numbers & Peano stuff, no need for construction of rationals, irrationals, logarithms, etc.