How to prove that 1 = 2:

1 = 2 
2 = 4 (*2)
-1 = 1 (-3)
1 = 1 (^2)

You can just multiply both sides by 0, but that's cheating. This is just bending the rules a little bit.

Your challenge:

Write a program/function that, when given two integers, outputs a "proof" that the two are equal.


  • Your program's output must start with a = b, where a and b are the integers, and end with c = c, where c can be any number. Don't output the operations.
  • Your output can only use integers.
  • The only operations you can use are addition, multiplication, division, subtraction, and exponentiation, and you cannot multiply, divide or exponentiate by 0.
  • Each line must be one of the above operations done to both sides of the equation in the previous line.

For example, you could go:

4 = 9
5 = 10 (+1)
1 = 2 (/5)
8 = 16 (*8)
-4 = 4 (-12)
16 = 16 (^2)


This is , shortest wins!

  • \$\begingroup\$ Sandboxed. Going to sleep now, will try to clarify stuff later. \$\endgroup\$
    – emanresu A
    Jun 1, 2021 at 11:46
  • 4
    \$\begingroup\$ Alternatively phrased, this is equivalent to finding the steps from an input \$(a, b)\$ to \$(-n, n)\$ for some integer \$n\$, where the "steps" are the 5 provided operators \$\endgroup\$ Jun 1, 2021 at 11:55
  • 2
    \$\begingroup\$ May we assume that a≠b? \$\endgroup\$ Jun 1, 2021 at 11:57
  • 7
    \$\begingroup\$ From the sandbox: It's worth mentioning that for any a=b as input you can always do the steps a=b;2a=2b (*2); a-b=b-a (-(a+b));a^2-2ab+b2=a^2-2ab+b2 (^2). Sometimes you can do faster but there is not much reason to do anything more complex than (*2)->(-(a+b))->(^2). \$\endgroup\$
    – Wheat Wizard
    Jun 1, 2021 at 15:49
  • 2
    \$\begingroup\$ Must I separate integers and an equal sign with a space? \$\endgroup\$
    – user100411
    Jun 2, 2021 at 12:20

14 Answers 14


JavaScript (Node.js), 57 54 bytes


Try it online!


There always exists a multiple of \$0.5\$ which, when subtracted from each number, creates a pair of the form \$-a = a\$. If \$a-x=c\$, then \$b-(a-x+b)=-c\$, so then if \$a-x+b=x\$, then \$x=\frac{(a+b)}2\$. This might not be an integer, so multiply by 2 beforehand.

-3 bytes thanks to Arnauld.


05AB1E, 13 12 bytes


Try it online!

A port of my Jelly answer. I thought that 05AB1E's stack-based functionality would be shorter, but it isn't great at joining.

-1 byte thanks to ovs!

xIÂ-Dn)'=δý» - Full program. Takes [a, b] on the stack
x            - Push [2a, 2b];   Stack = [[a, b], [2a, 2b]]
 I           - Push [a, b];     Stack = [[a, b], [2a, 2b], [a, b]]
  Â          - Bifurcate;       Stack = [[a, b], [2a, 2b], [a, b], [b, a]]
   -         - Subtract;        Stack = [[a, b], [2a, 2b], [a-b, b-a]]
    D        - Duplicate;       Stack = [[a, b], [2a, 2b], [a-b, b-a], [a-b, b-a]]
     n       - Square;          Stack = [[a, b], [2a, 2b], [a-b, b-a], [(a-b)², (b-a)²]]
      )      - Wrap into array; Stack = [[[a, b], [2a, 2b], [a-b, b-a], [(a-b)², (b-a)²]]]
       '=    - Push '='
         δý  - Join each with '='
           » - Join array by newlines
  • \$\begingroup\$ A few 12-byters. '=δý uses double-vectorize (δ), the other ones use that » joins inner lists by spaces. \$\endgroup\$
    – ovs
    Jun 1, 2021 at 14:52
  • \$\begingroup\$ @ovs Nice! I think I'll go with the first one, δ`` seems a lot easier to understand than either #` or :, especially in the context of » \$\endgroup\$ Jun 1, 2021 at 15:00

R, 64 51 bytes

-7 bytes thanks to Dominic van Essen.


Try it online!

The steps followed are:

a = b
2a = 2b (*2)
a-b = b-a (-(a+b))
(a-b)^2 = (b-a)^2 (^2)
  • \$\begingroup\$ 55 bytes by changing step 3 to 'subtract both sides from a+b' instead of 'subtract a+b from both sides' and rearranging a bit... \$\endgroup\$ Jun 1, 2021 at 21:45
  • \$\begingroup\$ @DominicvanEssen Thanks, but the way I read the rules, I think that would require 2 steps (first multiply by -1, then add a+b). Putting sep up front is a great idea! \$\endgroup\$ Jun 1, 2021 at 22:00
  • \$\begingroup\$ This should be Ok though...? \$\endgroup\$ Jun 2, 2021 at 0:06
  • \$\begingroup\$ @DominicvanEssen Very nice! \$\endgroup\$ Jun 2, 2021 at 13:11

Jelly, 14 bytes


Try it online!

Uses ophact's observation, that for any \$a, b\$, it is sufficient to yield the 4 equations

$$ a = b \\ 2a = 2b \\ a-b = b-a \\ (a-b)^2 = (b-a)^2 $$

How it works

,Ḥ;_U,²$Ɗj€”=Y - Main link. Takes [a, b] on the left
 Ḥ             - Double, yielding [2a, 2b]
,              - Pair; [[a, b], [2a, 2b]]
        Ɗ      - Previous three links as a monad f([a, b]):
    U          -   Reverse; [b, a]
   _           -   Subtract; [a-b, b-a]
       $       -   Previous two links as a monad f([a-b, b-a]]):
      ²        -     Square; [(a-b)², (b-a)²]
     ,         -     Pair; [[a-b, b-a], [(a-b)², (b-a)²]]
  ;            - Concatenate; [[a, b], [2a, 2b], [[a-b, b-a], [(a-b)², (b-a)²]]
         j€”=  - Join each with "="
             Y - Join with newlines

Python 2, 79 78 bytes

for x in'input()','2*a,2*b','a-b>>1,b-a>>1','a*a,'*2:a,b=eval(x);print a,'=',b

Try it online!

Python 3, 70 bytes

def f(a,b):x=a-b;return f'{a}={b}\n{2*a}={2*b}\n{x}={-x}\n{x*x}={x*x}'

Try it online!

  • 1
    \$\begingroup\$ I actually pointed out this method in the sandbox before ophact. But early bird gets the worm. \$\endgroup\$
    – Wheat Wizard
    Jun 1, 2021 at 15:54
  • \$\begingroup\$ @WheatWizard I did not look at the sandbox before posting. \$\endgroup\$
    – user100690
    Jun 1, 2021 at 18:15
  • \$\begingroup\$ With Python 3.8 you can get 64 bytes. \$\endgroup\$ Jun 1, 2021 at 22:09

Python 2, 84 \$\cdots\$ 73 71 bytes

Saved 5 bytes thanks to ovs!!!
Saved 2 bytes thanks to dingledooper!!!

for a,b in k,[2*a,2*b],[d,-d],[d*d]*2:print a,'=',b

Try it online!

  • \$\begingroup\$ 73 bytes as a full program (or 75 if you keep it as function). \$\endgroup\$
    – ovs
    Jun 1, 2021 at 20:23
  • \$\begingroup\$ @ovs Nice one - thanks! :D \$\endgroup\$
    – Noodle9
    Jun 1, 2021 at 20:56
  • \$\begingroup\$ 71 bytes \$\endgroup\$ Jun 1, 2021 at 22:05
  • 1
    \$\begingroup\$ 61 bytes \$\endgroup\$
    – Makonede
    Jun 2, 2021 at 0:16
  • 1
    \$\begingroup\$ 54 bytes with Python 3.8's walrus operator. \$\endgroup\$ Jun 2, 2021 at 3:17

C (clang), 65 bytes

#define r;printf("%d=%d\n",a

Try it online! Uses ophact's approach.

Using clang instead of gcc saves a byte, as clang handles the undefined behavior in the second printf differently than gcc:


The order of the arguments' evaluation is unspecified. In gcc, the -a is evaluated before a-=b; thus, the second argument is not affected by the subtraction and must be b-a to get the proper value. However, in clang, the a-=b is evaluated first so the second argument is affected by the subtraction so -a is the correct value.

C (gcc), 76 74 66 bytes

-8 bytes thanks to tsh

#define r;printf("%d=%d\n",a

Try it online!

  • \$\begingroup\$ 66: #define r;printf("%d=%d\n",a f(a,b){r,b)r+a,b+b)r-=b,b-a)r*=a,a);} \$\endgroup\$
    – tsh
    Jun 4, 2021 at 8:21

Charcoal, 20 bytes


Try it online! Link is to verbose version of code. Takes input as a list [a, b]. Explanation: Based on @ophact's approach.


Vectorised subtract the sum of the list from its double, thus giving [a-b, b-a].


Loop over the lists [a, b], 2[a, b], [a-b, b-a] and [a-b, b-a]², joining each list with = and implicitly printing them on separate lines.


C# (Visual C# Interactive Compiler), 50 bytes

Same as the javascript but using C#'s "superior code golfing" interpolation


Try it online!


Vyxal j, 12 bytes


Try it Online!

Why write your own original answer when you can just port 05ab1e amiright? :p


:d           # [a, b], [2a, 2b]
  ?Ḃ-        # [a - b], [b - a]
     :²      # that, but squared
       Wƛ\=j # join each on "=" and then join that on newlines with the j flag

Julia 1.0, 48 bytes

port of ophact's answer


Try it online!

alternative answer, 48 bytes too

output is a list of strings


Try it online!


Python 3, 72 bytes

f=lambda a,b:f"{a}={b}\n{2*a}={2*b}\n{a-b}={b-a}\n{(a-b)**2}={(a-b)**2}"

Uses ophact's observation to answer in 4 steps.

Try it online!

  • \$\begingroup\$ Nice! You can save two bytes by going a+f"= at the start and ="+(a-b)**2 at the end. \$\endgroup\$
    – emanresu A
    Jun 8, 2021 at 4:24
  • \$\begingroup\$ @Ausername That would be attempting to concatenate an integer and a string, which Python doesn't allow. Thanks anyway! \$\endgroup\$ Jun 8, 2021 at 10:50
  • \$\begingroup\$ Sorry, I'm used to Javascript. \$\endgroup\$
    – emanresu A
    Jun 8, 2021 at 11:02
  • \$\begingroup\$ @Ausername Oh, ok. Javascript has a lot of strange type conversions (e.g. []+[] gives ""), so that makes sense. \$\endgroup\$ Jun 8, 2021 at 11:23

GolfScript, 37 bytes

~:%;:$' = ':&%n$2*&%2*n$%-&%$-.n\2?.&\

Try it online!


Desmos, 207 characters

Try it online!

Organized for readability


<input 1>
<input 2>
<input 3>
m=-(a+b)/2                           #Parenthesises placed here to show that addition occurs before addition; they don't appear in actual graph
                                    #LABELS (From higher to lower)


a and b are the starting numbers, and c is the target number. Like my other programs, ans_n correspond to the line number, acting as inputs.

m is the midpoint of a and b. The reason that it is subtracted from a and b is so that they become equidistant from 0. NOTE: m is negative simply for formatting the proof; simply treat it as a positive and that all operations involving it are subtractions.

d is simply the distance between c and (a-m)^2. The squaring ensures that the term is positive, making both sides of the equation equal to each other. From there, the distance is added on to the result, making both sides of the equation equal to c.

l and l_1 are lists. This is used to provide the labels. From left to right, the terms in the lists are as follows: the input, the input minus m, the square of (the input minus m), and the square of (the input minus m) plus d.

The first point, (-1,[0,-1,-2,-3]), uses ${l} as a label. The list within the point creates multiple copies of the point at those y values, and the label uses the corresponding value from l to make it have the corresponding value on the graph. For example, (-1,0) would have a as its label. Likewise, the third point, (1,[0,-1,-2,-3]), would use l_1 to produce its labels in a similar manner. The second point, however, would simply have the label be =.

Point (4,0) has the label (given), which is self explanatory.

Point (4,-1) has the label (${m}), which uses m to produce the label of (m).

Point (4,-2) has the label (`^2`). The backticks are used to format the ^2 as a square and not as ^2.

Point (4,-3) has the label (${d}), which uses d to produce the label of (d).

  • \$\begingroup\$ a=ans_0 (and the other ans's) doesn't paste correctly; you will need to add a backslash in front of every single one of them. For example, a=\ans_0 \$\endgroup\$
    – Aiden Chow
    Jul 7, 2022 at 1:26
  • \$\begingroup\$ Also could you provide the code without any comments in them? I'm not seeing how you are getting 207 bytes. \$\endgroup\$
    – Aiden Chow
    Jul 7, 2022 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.