# Write a program that makes 2 + 2 = 5 [closed]

Write a program that seemingly adds the numbers 2 and 2 and outputs 5. This is an underhanded contest.

Your program cannot output any errors. Watch out for memory holes! Input is optional.

Redefining 2+2 as 5 is not very creative! Don't doublethink it, try something else.

• This is question in book "1984" by George Orwelll. – bacchusbeale May 30 '14 at 12:23
• Why is this underhanded? Two plus two is five. – Geobits May 30 '14 at 16:23
• THERE! ARE! FOUR! LIGHTS! – Nick T May 30 '14 at 19:57
• @Geobits - I agree: 2+2=5 you can see it in this calculator. – MT0 May 30 '14 at 20:03
• echo "2+2=5"; – user3459110 May 31 '14 at 12:16

## PHP

Here are 2 methods I found working

Method 1

echo (2+2 === '4' ? 4 : 5);


Method 2

$a =$b = 2;
echo ($a + ++$b);


Python 2.7 a emotional answer to the problem

# Code and error numbers for all errors that can occur.
error_number = 53
error_descrption = "Error occured"

try:
bird;
"""

This is the lead motive of our application.
This was made by jrei (http://www.chris.com/ascii/index.php?art=animals/birds%20(land))

_,---._      __,...-----...___
_,-:::,,--.,--''                 '--._
,':::::/((##)):                           -.
,':.::::/  --' :         _____.....______ (:::\
/:::::::/        :__,.-''''..- - - - --  -- ._-:\
/:,:::.::|        ::.          ____....-----......
/,:::::::/          ::::__.--'''
|:::::::|           _:'
|:.:::::|         ,'
|:::::::|         |
/::::.:::|         |
__,-'::.::::::|         |
_,.--''::::_::::::::::\        |
''::_::,:--''  '--.:::::\       ;
-'''::::::::::::::::\:::::.     ;
:::::::::::::::::::::|:.::::-..-
::;::::::::::::::::::|::::::::::/
:/::::::/::::::;:::::|::::.::::/
(::::::/::::::/::::::):.::::::'
::__,;::::::;:::::,':::::::'
,-':::.__,-'::::,'::::::-'
:::::,-'::::::,-':::_:-'
_,-':::::::,-'::_:-'
jrei::::,-_:--''
::,::--''

I think it resembles our application the best.
The strength and the speed of the bird are the same characteristics as our
application.

So dear reader enough talk, now comes the code which makes the application so
incredible! Buckle up your seatbelts! It will be a tough ride.

"""

print "{}".format(2+2)

"""
Oh dear reader i forgot to show you, how this program actually is structured.
I think the best way is UML, because everybody loves it.

+--------+       +---------------------+ *
| Client |------>| Component           |<-------------------------+
+--------+       +---------------------+                          |
| Operation()         |                          |
| Add(Component)      |                          |
| Remove(Component)   |                          |
| GetChild(int)       |                          |
+---------------------+                          |
#                                      |
|                                      |
+----------+--------------+                       |
|                         |                       |
+------+------+   +----------+----------+  children   |
| Leaf        |   | Composite           |O------------+
+-------------+   +---------------------+
| Operation() |   | Operation()         |
+-------------+   | Add(Component)      |
| Remove(Component)   |
| GetChild(int)       |
+---------------------+

I especially want to say thank you to all people, which where part of this project.
It took me several weeks to code this stuff and went through a hard time.
My wife broke up with me and my dog died. I am a very emotional person,
and this hit me really hard. But it is very nice, that i have somebody like you,
someon i can talk to. I think this code is the fastest implementation on out there.
I am very proud of it and it gives me the strength to go on with my life.
Although i miss my wife, this is the past. I need to find a way to look into the future.
I am a little bit overweight, but i do workouts to get fit.
I try to avoid hotdogs, but they are just so jummy. But i will find the inner
strength to avoid them.

Thank you very much.
Sincerely (insert name here)

"""
# Just some basic handling error in the case something goes wrong
# My Code is perfectly fine (insert link to xkcd comic here), but you never know
except NameError:
try:
print chr(error_number), error_description
except NameError:
pass

• Took me 30 seconds to see the error. – kirbyfan64sos Nov 6 '15 at 15:47

Because we love to trust in the docstring and our debug decorators.

from functools import wraps

def debug(func):
@wraps(func)
def wrapper(*args):
print "*DEBUG"
print "**Calling help on %s" % func.__name__
help(func)
print "** Executing %s(a=%s,b=%s)" % (func.__name__,args[0],args[1])
print "**%s + %s = " % (args[0], args[1]),
return func(args[0] + 1, args[1])

return wrapper

@debug
"""
:param a: default 2
:type a: int
:param b: default 2
:type b: int
:returns: a+b
:rtype: int
"""
return a + b


• This is not hidden at all: return func(args[0] + 1, args[1]). – Kyle Kanos Jul 17 '14 at 14:56
• It's a practical joke. Because we usually trust in the docstring and the debugger. If something like this happens deep down a big program, you don't have a simple way to track it down because the @wraps changes the 'wrapped' to the add(). – f.rodrigues Jul 17 '14 at 15:27

C#

Console.WriteLine(" 2+2=".Length);

• That doesn't really look like it should print 4, does it? ;) – Martin Ender Dec 31 '14 at 10:17

Simply write it down using the boolean equality operator or define an another addition function using the + character ...

C#

Didn't see anyone write this I think...

    static void Main(string[] args)
{
int two = 2;

int answer = two + two;

if (answer == 4)
{
`