Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

61%
+6 −3
Challenges Make $2 + 2 = 5$

In this challenge, add 2 integers, but if both the integers are 2, output 5. Shortest code in each language wins! Example ungolfed program in Python 3.x def add(x, y): if x == 2 and y == 2: ...

22 answers  ·  posted 3y ago by General Sebast1an‭  ·  last activity 20h ago by xrs‭

Question code-golf math number
#3: Post edited by user avatar user‭ · 2021-09-26T21:29:07Z (about 3 years ago)
Don't use "program" or "function"
Make $2 + 2 = 5$
  • In this challenge, make a program that adds 2 integers, preferably on a function, and if the statement is `2 + 2`, return or print `5`. Shortest program in each language wins!
  • # Example ungolfed program in [Python 3.x]
  • <!-- language-all: lang-python -->
  • <pre><code>def add(x, y):
  • &#9;if x == 2 and y == 2:
  • &#9;&#9;return 5
  • &#9;else:
  • &#9;&#9;return x + y
  • </code></pre>
  • [Try it online!][TIO-ksu80pvu]
  • [Python 3.x]: https://docs.python.org/3/
  • [TIO-ksu80pvu]: https://tio.run/##Vcy9CoAgGEbhWa/iHf3ISWkJvBhBJSFMzECv3n6m2g7PcHKv6570GM4HWOdEk@i0cBYDGoyBgk0O/c2bWfH1LAkzZ347/EcaJnTOc4mpiuekJBTRHzTRGBc "Python 3 – Try It Online"
  • In this challenge, add 2 integers, but if both the integers are `2`, output `5`. Shortest code in each language wins!
  • # Example ungolfed program in [Python 3.x]
  • <!-- language-all: lang-python -->
  • <pre><code>def add(x, y):
  • &#9;if x == 2 and y == 2:
  • &#9;&#9;return 5
  • &#9;else:
  • &#9;&#9;return x + y
  • </code></pre>
  • [Try it online!][TIO-ksu80pvu]
  • [Python 3.x]: https://docs.python.org/3/
  • [TIO-ksu80pvu]: https://tio.run/##Vcy9CoAgGEbhWa/iHf3ISWkJvBhBJSFMzECv3n6m2g7PcHKv6570GM4HWOdEk@i0cBYDGoyBgk0O/c2bWfH1LAkzZ347/EcaJnTOc4mpiuekJBTRHzTRGBc "Python 3 – Try It Online"
#2: Post edited by user avatar General Sebast1an‭ · 2021-09-07T10:30:57Z (about 3 years ago)
  • In this challenge, make a program that adds 2 integers, preferably on a function, and if the statement is `2 + 2`, return `5`. Shortest program in each language wins!
  • # Example ungolfed program in [Python 3.x]
  • <!-- language-all: lang-python -->
  • <pre><code>def add(x, y):
  • &#9;if x == 2 and y == 2:
  • &#9;&#9;return 5
  • &#9;else:
  • &#9;&#9;return x + y
  • </code></pre>
  • [Try it online!][TIO-ksu80pvu]
  • [Python 3.x]: https://docs.python.org/3/
  • [TIO-ksu80pvu]: https://tio.run/##Vcy9CoAgGEbhWa/iHf3ISWkJvBhBJSFMzECv3n6m2g7PcHKv6570GM4HWOdEk@i0cBYDGoyBgk0O/c2bWfH1LAkzZ347/EcaJnTOc4mpiuekJBTRHzTRGBc "Python 3 – Try It Online"
  • In this challenge, make a program that adds 2 integers, preferably on a function, and if the statement is `2 + 2`, return or print `5`. Shortest program in each language wins!
  • # Example ungolfed program in [Python 3.x]
  • <!-- language-all: lang-python -->
  • <pre><code>def add(x, y):
  • &#9;if x == 2 and y == 2:
  • &#9;&#9;return 5
  • &#9;else:
  • &#9;&#9;return x + y
  • </code></pre>
  • [Try it online!][TIO-ksu80pvu]
  • [Python 3.x]: https://docs.python.org/3/
  • [TIO-ksu80pvu]: https://tio.run/##Vcy9CoAgGEbhWa/iHf3ISWkJvBhBJSFMzECv3n6m2g7PcHKv6570GM4HWOdEk@i0cBYDGoyBgk0O/c2bWfH1LAkzZ347/EcaJnTOc4mpiuekJBTRHzTRGBc "Python 3 – Try It Online"
#1: Initial revision by user avatar General Sebast1an‭ · 2021-08-27T10:46:44Z (about 3 years ago)
Make $2 + 2 = 5$
In this challenge, make a program that adds 2 integers, preferably on a function, and if the statement is `2 + 2`, return `5`. Shortest program in each language wins!

# Example ungolfed program in [Python 3.x]

<!-- language-all: lang-python -->

<pre><code>def add(x, y):
&#9;if x == 2 and y == 2:
&#9;&#9;return 5
&#9;else:
&#9;&#9;return x + y
</code></pre>

[Try it online!][TIO-ksu80pvu]

[Python 3.x]: https://docs.python.org/3/
[TIO-ksu80pvu]: https://tio.run/##Vcy9CoAgGEbhWa/iHf3ISWkJvBhBJSFMzECv3n6m2g7PcHKv6570GM4HWOdEk@i0cBYDGoyBgk0O/c2bWfH1LAkzZ347/EcaJnTOc4mpiuekJBTRHzTRGBc "Python 3 – Try It Online"