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

50%
+0 −0
Challenges Make $2 + 2 = 5$

Java (JDK), 51 50 23 21 bytes x->y->x==y&y==2?5:x+y Try it online! Golfed 27 bytes thanks to @Moshi's advice. Golfed 2 bytes thanks to @user's advice on Discord.

posted 3y ago by General Sebast1an‭  ·  edited 3y ago by General Sebast1an‭

Answer
#5: Post edited by user avatar General Sebast1an‭ · 2021-10-17T14:53:04Z (about 3 years ago)
  • # [Java (JDK)], <s>51</s> <s>50</s> <s>23</s> 21 bytes
  • <!-- language-all: lang-java -->
  • x->y->x==y&y==2?5:x+y
  • [Try it online!][TIO-kuvcg8wh]
  • Golfed 27 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4840#comment-14340). Golfed a byte thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s advice on Discord.
  • [Java (JDK)]: http://jdk.java.net/
  • [TIO-kuvcg8wh]: https://tio.run/##jc49D4IwEAbgmf6KTgaiNIK6iK2biYMTo3Fo@EoRCikHoTH89toYdJXtTe55767kA/fL9GmEhEzlPMnwjQv5Qhh3wEEkuLSC9CAqkvcyAdFIcpnD6WpLRaY2y9AcGMM5pmb0mfbZSKleaUrD8@E4rrWJHDTfHRqR4tr@4saghCzuD8xV0Xkv5Dix7iCrSdMDae0MKunmhLdtpd3Q@wUvWkh3f@l@@dZg@7XBx05oMm8 "Java (JDK) – Try It Online"
  • # [Java (JDK)], <s>51</s> <s>50</s> <s>23</s> 21 bytes
  • <!-- language-all: lang-java -->
  • x->y->x==y&y==2?5:x+y
  • [Try it online!][TIO-kuvcg8wh]
  • Golfed 27 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4840#comment-14340). Golfed 2 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s advice on Discord.
  • [Java (JDK)]: http://jdk.java.net/
  • [TIO-kuvcg8wh]: https://tio.run/##jc49D4IwEAbgmf6KTgaiNIK6iK2biYMTo3Fo@EoRCikHoTH89toYdJXtTe55767kA/fL9GmEhEzlPMnwjQv5Qhh3wEEkuLSC9CAqkvcyAdFIcpnD6WpLRaY2y9AcGMM5pmb0mfbZSKleaUrD8@E4rrWJHDTfHRqR4tr@4saghCzuD8xV0Xkv5Dix7iCrSdMDae0MKunmhLdtpd3Q@wUvWkh3f@l@@dZg@7XBx05oMm8 "Java (JDK) – Try It Online"
#4: Post edited by user avatar General Sebast1an‭ · 2021-10-17T14:52:28Z (about 3 years ago)
  • # [Java (JDK)], <s>51</s> <s>50</s> 23 bytes
  • <!-- language-all: lang-java -->
  • (x,y)->x==y&y==2?5:x+y;
  • [Try it online!][TIO-kutdl4wl]
  • Golfed 27 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4840#comment-14340).
  • [Java (JDK)]: http://jdk.java.net/
  • [TIO-kutdl4wl]: https://tio.run/##XY1PS8QwEMXP7acYFpTUZoMIe7GbXfAgePC0R/UQ@4/JtklppkuD9LPX1C4KHuY93sxvZrS6qK0uzjO2ne0JdMhiIGxENZic0Bpxl8Xd8NlgDnmjnINXhQa@4ujadKQo2MViAW0YsRP1aOq3D1B97ZKFjJ7w@Xpt/2KorMue//MDVCBhZiP3yfYwSulvvZQPx93jmPpsjqLK9sDQEGDg7rNge9gFS9P1xR@gV0CvgP4FopN3VLbCDiQC3Cpim5sCUggig7ybDQfkoDlUQnVd49mSkiRbtqf4p6Z4mr8B "Java (JDK) – Try It Online"
  • # [Java (JDK)], <s>51</s> <s>50</s> <s>23</s> 21 bytes
  • <!-- language-all: lang-java -->
  • x->y->x==y&y==2?5:x+y
  • [Try it online!][TIO-kuvcg8wh]
  • Golfed 27 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4840#comment-14340). Golfed a byte thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s advice on Discord.
  • [Java (JDK)]: http://jdk.java.net/
  • [TIO-kuvcg8wh]: https://tio.run/##jc49D4IwEAbgmf6KTgaiNIK6iK2biYMTo3Fo@EoRCikHoTH89toYdJXtTe55767kA/fL9GmEhEzlPMnwjQv5Qhh3wEEkuLSC9CAqkvcyAdFIcpnD6WpLRaY2y9AcGMM5pmb0mfbZSKleaUrD8@E4rrWJHDTfHRqR4tr@4saghCzuD8xV0Xkv5Dix7iCrSdMDae0MKunmhLdtpd3Q@wUvWkh3f@l@@dZg@7XBx05oMm8 "Java (JDK) – Try It Online"
#3: Post edited by user avatar General Sebast1an‭ · 2021-10-16T05:46:03Z (about 3 years ago)
  • # [Java (JDK)], <s>51</s> 50 bytes
  • <!-- language-all: lang-java -->
  • static int f(int x,int y){return x==y&y==2?5:x+y;}
  • [Try it online!][TIO-kuta6k7i]
  • [Java (JDK)]: http://jdk.java.net/
  • [TIO-kuta6k7i]: https://tio.run/##fYyxDoIwFEVn@IpOpo2VCOoiafwCJ0bj0EAhBSmmPEibhm@vxbjKcoZ7cm7LZ35oq85LBULXvBTozqVyfgQOskRhRjVeaehKS5wWMGmFDGN2ZxnLbper2dt88dGvmQdZoT684AK0VM3jibhuRuLiKCrsCKJPhgmSd3DwUrjGGc0Iyf/b04Y9b7bpkaZfvcSL/wA "Java (JDK) – Try It Online"
  • # [Java (JDK)], <s>51</s> <s>50</s> 23 bytes
  • <!-- language-all: lang-java -->
  • (x,y)->x==y&y==2?5:x+y;
  • [Try it online!][TIO-kutdl4wl]
  • Golfed 27 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4840#comment-14340).
  • [Java (JDK)]: http://jdk.java.net/
  • [TIO-kutdl4wl]: https://tio.run/##XY1PS8QwEMXP7acYFpTUZoMIe7GbXfAgePC0R/UQ@4/JtklppkuD9LPX1C4KHuY93sxvZrS6qK0uzjO2ne0JdMhiIGxENZic0Bpxl8Xd8NlgDnmjnINXhQa@4ujadKQo2MViAW0YsRP1aOq3D1B97ZKFjJ7w@Xpt/2KorMue//MDVCBhZiP3yfYwSulvvZQPx93jmPpsjqLK9sDQEGDg7rNge9gFS9P1xR@gV0CvgP4FopN3VLbCDiQC3Cpim5sCUggig7ybDQfkoDlUQnVd49mSkiRbtqf4p6Z4mr8B "Java (JDK) – Try It Online"
#2: Post edited by user avatar General Sebast1an‭ · 2021-10-16T04:10:21Z (about 3 years ago)
  • # [Java (JDK)], 51 bytes
  • <!-- language-all: lang-java -->
  • static int f(int x,int y){return x==y&&y==2?5:x+y;}
  • [Try it online!][TIO-kut9t01n]
  • [Java (JDK)]: http://jdk.java.net/
  • [TIO-kut9t01n]: https://tio.run/##fYyxDoIwFEXn8hWdSBsrEdRF0vgFTozGoYGWFKWY8iA0hG@vxbjKcoZ7cm4jRrFvqqfXBqRVopT4JrSZfQ8CdInDjBVZObGVjs5WwmANnjh3cew4z67ny7Rz@eLRLxo7XeE23JACrDb1/YGFrXs6RwgVrgfZJt0AyTs4eBmiSMYySvP/9rhhT5ttemDpVy/R4j8 "Java (JDK) – Try It Online"
  • # [Java (JDK)], <s>51</s> 50 bytes
  • <!-- language-all: lang-java -->
  • static int f(int x,int y){return x==y&y==2?5:x+y;}
  • [Try it online!][TIO-kuta6k7i]
  • [Java (JDK)]: http://jdk.java.net/
  • [TIO-kuta6k7i]: https://tio.run/##fYyxDoIwFEVn@IpOpo2VCOoiafwCJ0bj0EAhBSmmPEibhm@vxbjKcoZ7cm7LZ35oq85LBULXvBTozqVyfgQOskRhRjVeaehKS5wWMGmFDGN2ZxnLbper2dt88dGvmQdZoT684AK0VM3jibhuRuLiKCrsCKJPhgmSd3DwUrjGGc0Iyf/b04Y9b7bpkaZfvcSL/wA "Java (JDK) – Try It Online"
#1: Initial revision by user avatar General Sebast1an‭ · 2021-10-16T03:59:20Z (about 3 years ago)
# [Java (JDK)], 51 bytes

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

    static int f(int x,int y){return x==y&&y==2?5:x+y;}

[Try it online!][TIO-kut9t01n]

[Java (JDK)]: http://jdk.java.net/
[TIO-kut9t01n]: https://tio.run/##fYyxDoIwFEXn8hWdSBsrEdRF0vgFTozGoYGWFKWY8iA0hG@vxbjKcoZ7cm4jRrFvqqfXBqRVopT4JrSZfQ8CdInDjBVZObGVjs5WwmANnjh3cew4z67ny7Rz@eLRLxo7XeE23JACrDb1/YGFrXs6RwgVrgfZJt0AyTs4eBmiSMYySvP/9rhhT5ttemDpVy/R4j8 "Java (JDK) – Try It Online"