News for hackers. Stuff that matters.
Re:Making any integer with four 2s (2025) by gnabgib on Saturday November 07, 2026 @05:48PM (#50408765)
Popular last year (368 points, 165 comments) https://news.ycombinator.com/item?id=43145753
Re:Making any integer with four 2s (2025) by Arnt on Saturday November 07, 2026 @06:16PM (#50408970)
Spoilsport.

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

Re:Making any integer with four 2s (2025) by teo_zero on Saturday November 07, 2026 @06:18PM (#50408980)
Never understood why 7 is considered difficult...

7 = ⌈ 2.2² + 2 ⌉

Re:Making any integer with four 2s (2025) by Jtsummers on Saturday November 07, 2026 @06:29PM (#50409038)
[delayed]
Re:Making any integer with four 2s (2025) by AnimalMuppet on Saturday November 07, 2026 @07:06PM (#50409264)
It is difficult when the rules do not allow exponentiation.
Re:Making any integer with four 2s (2025) by Jtsummers on Saturday November 07, 2026 @07:28PM (#50409397)
[delayed]
Re:Making any integer with four 2s (2025) by blueblock on Saturday November 07, 2026 @07:29PM (#50409408)
Rounding spoils the fun of the puzzle.
Re:Making any integer with four 2s (2025) by nostrademons on Saturday November 07, 2026 @08:14PM (#50409633)
It seems very much in the spirit of allowing concatenation and square roots...
Re:Making any integer with four 2s (2025) by jtari3333 on Sunday November 08, 2026 @03:41AM (#50411476)
Rounding is a completely valid mathematical operation.
Re:Making any integer with four 2s (2025) by anthk on Saturday November 07, 2026 @10:23PM (#50410160)
(2 << 2) - ( 2 / 2)
Re:Making any integer with four 2s (2025) by adas0693 on Saturday November 07, 2026 @06:55PM (#50409188)
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;

Re:Making any integer with four 2s (2025) by genter on Saturday November 07, 2026 @06:59PM (#50409216)
Are you allowed to brute force it?
Re:Making any integer with four 2s (2025) by argee on Saturday November 07, 2026 @08:16PM (#50409649)
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.
Re:Making any integer with four 2s (2025) by twoodfin on Sunday November 08, 2026 @08:23AM (#50413092)
Given the problems ITA solved, thinking about the question that way makes perfect sense.
Re:Making any integer with four 2s (2025) by dooglius on Saturday November 07, 2026 @11:59PM (#50410524)
Figuring that out is presumably part of the interview (and would depend on N)
Re:Making any integer with four 2s (2025) by catlifeonmars on Saturday November 07, 2026 @08:27PM (#50409706)
[delayed]
Re:Making any integer with four 2s (2025) by hahajk on Saturday November 07, 2026 @08:43PM (#50409769)
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
Re:Making any integer with four 2s (2025) by JumpCrisscross on Saturday November 07, 2026 @09:12PM (#50409891)
> 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.

Re:Making any integer with four 2s (2025) by danparsonson on Saturday November 07, 2026 @09:29PM (#50409956)
Would you elaborate on that? That doesn't make any sense to me
Re:Making any integer with four 2s (2025) by drfloyd51 on Saturday November 07, 2026 @10:12PM (#50410111)
Multiplication is repeated addition.

2x3= 2+2+2 AxB= A+A B times.

Raising to a power is repeated multiplication.

2^3= 2x2x2 A^B = AxA B times

Roots are the inverse of powers

Division is the inverse of multiplications.

Given this… the OC’s comment about giving exceptions to powers in the rules is nonsense because they are still operations.

Re:Making any integer with four 2s (2025) by mojomark on Saturday November 07, 2026 @10:40PM (#50410234)
Multiplication is not the same as repeated addition, which you can observe as soon as you try the two different operations on fractions or negative numbers. For example, you can't add a number to itself 1/3 times, but you can certainly scale a number by 1/3.

Multiplication is a scaling operation.

Re:Making any integer with four 2s (2025) by goodmythical on Sunday November 08, 2026 @12:04AM (#50410541)
Can you not? 9+(9(1/3)) [adding nine to itself a third of a time] is nine plus one third of nine {or nine divided by three} which is one of the three in three times three that equals nine which is three therefore 9+(9(1/3))=11 because 9+3=11
Re:Making any integer with four 2s (2025) by alpaca128 on Sunday November 08, 2026 @05:51AM (#50412123)
9+3=12, but otherwise I agree
Re:Making any integer with four 2s (2025) by red369 on Sunday November 08, 2026 @08:05AM (#50412944)
:)

I like it when people who are clearly smart do things like this! Makes me feel better.

Reminds me of this story: https://news.ycombinator.com/item?id=5663709

Re:Making any integer with four 2s (2025) by srean on Sunday November 08, 2026 @08:35AM (#50413226)
That's Grothendieck multiplication.
Re:Making any integer with four 2s (2025) by mojomark on Sunday November 08, 2026 @09:36AM (#50413726)
By dividing by 3 you are introducing a scaler into the operation.

Multiplication also flips signs (direction). That's why a negative * negative = positive, whereas a negative + negative = negative. The addition operator does not flip direction.

Multiplication is not generally the same as multiple addition operations. However, it has the same result for positive whole numbers.

Re:Making any integer with four 2s (2025) by reichstein on Sunday November 08, 2026 @05:48AM (#50412108)
Multiplication is the generalization of repeated addition. Repeated addition can be generalized to fractional values.

In the integers, it is the same thing, with a rule for negative times.

In the rational numbers, you can generalize to adding a number to itself a rational number of times. Adding a/b to itself p/q times is defined as adding a to itself p times, with a divisor that is adding b to itself q times.

So adding the rational 5 (5/1) with itself 2_and-1/3 (4/3) times just means (5+5+5+5) / (1 + 1 + 1) = 20/3, a rational that we can also write as 6 -and-2/3. Only addition of integers is used.

Which is the same as rational multiplication (a/b)(p/q) = (ap)/(b*q).

But it's true that you can't say that rational multiplication is the same as _integer_ repeated addition.

Re:Making any integer with four 2s (2025) by anthk on Sunday November 08, 2026 @01:05PM (#50415554)
>you can't add a number to itself 1/3 times,

Learn logarithms.

Re:Making any integer with four 2s (2025) by spieglt on Saturday November 07, 2026 @10:14PM (#50410124)
Multiplication is adding numbers to themselves. Exponentiation is multiplying numbers by themselves. Ditto division/taking roots. Squaring a number is just the instance of exponentiation that happens to have two operands. If taking a square root is an inherent use of a two, then dividing a number by another number should also be a use of a two, because there are two operands.
Re:Making any integer with four 2s (2025) by jibalt on Saturday November 07, 2026 @11:18PM (#50410384)
Because it's just wrong. hahajk said that taking the 2nd root spends a 2, not that "roots are invalid".
Re:Making any integer with four 2s (2025) by epcoa on Saturday November 07, 2026 @09:33PM (#50409971)
I think you misunderstand. They’re saying (maybe not very well) that the square root is not really a unary operator, it’s a binary operator of which the “square root” symbol just elides the 2 in the left.

But the “rules” of this game are necessarily arbitrary.

Re:Making any integer with four 2s (2025) by penteract on Saturday November 07, 2026 @10:13PM (#50410112)
Exponentiation is to multiplication as multiplication is to addition. Squaring is to multiplication as doubling is to addition.
Re:Making any integer with four 2s (2025) by jolmg on Sunday November 08, 2026 @02:03AM (#50411057)
> Squaring is to multiplication as doubling is to addition.

as halving is to addition.

Re:Making any integer with four 2s (2025) by penteract on Sunday November 08, 2026 @02:22AM (#50411129)
Square rooting is to multiplication as halving is to addition.
Re:Making any integer with four 2s (2025) by SamBam on Saturday November 07, 2026 @10:31PM (#50410189)
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.

Re:Making any integer with four 2s (2025) by direwolf20 on Sunday November 08, 2026 @12:57AM (#50410794)
It can be written as ²√2 and there's also ³√2 and so on
Re:Making any integer with four 2s (2025) by schiffern on Sunday November 08, 2026 @06:04AM (#50412211)
Yep.

It would be like if we had a stylistic convention that you can drop the second number in an addition and it becomes 1. So "6 +" means "6 + 1."

Now I can trivially make any number, but I'm just 'exploiting' a convenience feature of the notation:

0 = 2 + 2 - 2 - 2

1 = 2 + 2 - 2 - 2 +

2 = 2 + 2 - 2 - 2 + +

Etc

Re:Making any integer with four 2s (2025) by Biganon on Sunday November 08, 2026 @07:22AM (#50412650)
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.
Re:Making any integer with four 2s (2025) by jibalt on Sunday November 08, 2026 @10:11PM (#50420561)
The obvious counterargument is that the problem statement is

> Given exactly four instances of the digit 2 and some target natural number, use any mathematical operations to generate the target number with these 2s, using no other digits.

and the square root symbol is a mathematical operation and is not a digit. That it is equivalent to taking the 2nd root isn't relevant ... the whole puzzle is about finding and using equivalents.

Re:Making any integer with four 2s (2025) by SideQuark on Saturday November 07, 2026 @09:15PM (#50409898)
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….

Re:Making any integer with four 2s (2025) by jjmarr on Saturday November 07, 2026 @11:17PM (#50410377)
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

Re:Making any integer with four 2s (2025) by schiffern on Sunday November 08, 2026 @05:56AM (#50412149)
Perfect answer, I hate it :)
Re:Making any integer with four 2s (2025) by shiandow on Sunday November 08, 2026 @07:39AM (#50412750)
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.

Re:Making any integer with four 2s (2025) by JadeNB on Sunday November 08, 2026 @11:42PM (#50421151)
> There's a 2 in the definition of sin :-)

How?

Re:Making any integer with four 2s (2025) by shiandow on Monday November 09, 2026 @03:14AM (#50422606)
sin(x) = (e^ix - e^-ix) / 2i
Re:Making any integer with four 2s (2025) by Personability on Monday November 09, 2026 @10:53AM (#50427244)
That's more an identity than a definition.
Re:Making any integer with four 2s (2025) by anthk on Sunday November 08, 2026 @01:04PM (#50415542)
Keep it simple.

2^2 - (2 / 2).

Re:Making any integer with four 2s (2025) by olmo23 on Monday November 09, 2026 @08:54AM (#50425631)
2 + 2 - (2/2).
Re:Making any integer with four 2s (2025) by ta2345fa59be on Sunday November 08, 2026 @03:54AM (#50411525)
Or use the successor operator.
Re:Making any integer with four 2s (2025) by bajard on Sunday November 08, 2026 @02:48AM (#50411229)
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.
[dead]
Re:Making any integer with four 2s (2025) by edflsafoiewq on Sunday November 08, 2026 @01:48PM (#50415865)
This and Dirac's trick are both writing the number in unary. Is there a way to write it with o(n) symbols?
Re:Making any integer with four 2s (2025) by shoo on Sunday November 08, 2026 @03:32PM (#50416865)
That's a fun question.

If we're allowed to introduce our own operators, we could concoct something like decimal notation

a . b := 10a + b

So we could write 90210 as 9 . 0 . 2 . 1 . 0 = S(S(S(S(S(S(S(S(S(0))))))))) . 0 . S(S(0)) . S(0) . 0

That doesn't quite work as it still depends upon a bunch of literal zeros. We could replace 0 with an operator Z() := 0, but that seems to be very much against the spirit of the challenge.

We could rewrite our ersatz decimal expression to only require a single zero & then evaluate a vector of functions f : N -> N across that zero, resulting in a vector of natural numbers, then reduce that vector to a single number with our `.` decimal notation operator.

Let M(fs, x) := (fs_1(x), ..., fs_n(x))

Let R(x) := x_1 . x_2 . ... . x_n

90210 = R(M((SSSSSSSSS, Id, SS, S, Id), 0))

the number of symbols to write a d-digit number this way is bounded by 10 + 10d = 10 + 10log_10(n)

Is this cheating / against the spirit of the challenge? Perhaps!

Re:Making any integer with four 2s (2025) by allywilson on Sunday November 08, 2026 @03:45AM (#50411490)
I'll just drop this here (yes, it's 4 instead of 2 - they're twice as good): https://fourmula.awsum.info/
Re:Making any integer with four 2s (2025) by Someone on Sunday November 08, 2026 @08:07AM (#50412948)
[delayed]
Re:Making any integer with four 2s (2025) by rav on Sunday November 08, 2026 @08:31AM (#50413182)
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.

Re:Making any integer with four 2s (2025) by vessenes on Sunday November 08, 2026 @08:49AM (#50413367)
You’ve got S(4) in the center there
Re:Making any integer with four 2s (2025) by jasomill on Sunday November 08, 2026 @12:32PM (#50415279)
From the text, the inner term was clearly intended to be "2-2+2-2".
Re:Making any integer with four 2s (2025) by vessenes on Sunday November 08, 2026 @08:19PM (#50419745)
I agree!
Re:Making any integer with four 2s (2025) by omoikane on Sunday November 08, 2026 @11:20AM (#50414557)
A recent IOCCC entry solves a related game of making integers out of variable number of constants (e.g. make expression using only "2" and basic operations, but any number of "2" can be used as opposed to always four):

https://www.ioccc.org/2025/kurdyukov/index.html

Re:Making any integer with four 2s (2025) by igor47 on Sunday November 08, 2026 @02:43PM (#50416417)
I had a teacher in middle school who would assign a version of this over winter break with the digits of the new year. I had a lot of fun with it in 1996. Sad to think she must've stopped in 2000...