Equal, sum or difference!












7












$begingroup$


Write shortest possible code that will return true if the two given integer values are equal or their sum or difference is 5.



Example test cases:



4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True


The shortest I could come up with in python2 is 56 characters long:



x=input();y=input();print all([x-y,x+y-5,abs(x-y)-5])<1









share|improve this question









New contributor




Vikrant Biswas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Just for info, you can reduce your 56 by 9 by replacing x=input();y=input() with x,y=input() and giving the input as 2 integers separated by a comma.
    $endgroup$
    – ElPedro
    47 mins ago






  • 1




    $begingroup$
    welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
    $endgroup$
    – Giuseppe
    33 mins ago
















7












$begingroup$


Write shortest possible code that will return true if the two given integer values are equal or their sum or difference is 5.



Example test cases:



4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True


The shortest I could come up with in python2 is 56 characters long:



x=input();y=input();print all([x-y,x+y-5,abs(x-y)-5])<1









share|improve this question









New contributor




Vikrant Biswas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Just for info, you can reduce your 56 by 9 by replacing x=input();y=input() with x,y=input() and giving the input as 2 integers separated by a comma.
    $endgroup$
    – ElPedro
    47 mins ago






  • 1




    $begingroup$
    welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
    $endgroup$
    – Giuseppe
    33 mins ago














7












7








7


1



$begingroup$


Write shortest possible code that will return true if the two given integer values are equal or their sum or difference is 5.



Example test cases:



4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True


The shortest I could come up with in python2 is 56 characters long:



x=input();y=input();print all([x-y,x+y-5,abs(x-y)-5])<1









share|improve this question









New contributor




Vikrant Biswas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




Write shortest possible code that will return true if the two given integer values are equal or their sum or difference is 5.



Example test cases:



4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True


The shortest I could come up with in python2 is 56 characters long:



x=input();y=input();print all([x-y,x+y-5,abs(x-y)-5])<1






code-golf decision-problem






share|improve this question









New contributor




Vikrant Biswas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Vikrant Biswas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 32 mins ago









Sok

3,607723




3,607723






New contributor




Vikrant Biswas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 57 mins ago









Vikrant BiswasVikrant Biswas

363




363




New contributor




Vikrant Biswas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Vikrant Biswas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Vikrant Biswas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • $begingroup$
    Just for info, you can reduce your 56 by 9 by replacing x=input();y=input() with x,y=input() and giving the input as 2 integers separated by a comma.
    $endgroup$
    – ElPedro
    47 mins ago






  • 1




    $begingroup$
    welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
    $endgroup$
    – Giuseppe
    33 mins ago


















  • $begingroup$
    Just for info, you can reduce your 56 by 9 by replacing x=input();y=input() with x,y=input() and giving the input as 2 integers separated by a comma.
    $endgroup$
    – ElPedro
    47 mins ago






  • 1




    $begingroup$
    welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
    $endgroup$
    – Giuseppe
    33 mins ago
















$begingroup$
Just for info, you can reduce your 56 by 9 by replacing x=input();y=input() with x,y=input() and giving the input as 2 integers separated by a comma.
$endgroup$
– ElPedro
47 mins ago




$begingroup$
Just for info, you can reduce your 56 by 9 by replacing x=input();y=input() with x,y=input() and giving the input as 2 integers separated by a comma.
$endgroup$
– ElPedro
47 mins ago




1




1




$begingroup$
welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
$endgroup$
– Giuseppe
33 mins ago




$begingroup$
welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
$endgroup$
– Giuseppe
33 mins ago










15 Answers
15






active

oldest

votes


















4












$begingroup$

JavaScript (ES6), 28 bytes



Takes input as (a)(b). Returns $0$ or $1$.





a=>b=>a+b==5|!(a-=b)|a*a==25


Try it online!






share|improve this answer











$endgroup$





















    2












    $begingroup$

    Python 2, 40 bytes





    lambda a,b:a+b==5 or abs(a-b)==5 or a==b


    Try it online!






    share|improve this answer









    $endgroup$













    • $begingroup$
      Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the 5s and the ors
      $endgroup$
      – ElPedro
      43 mins ago








    • 1




      $begingroup$
      Actually, the TIO link could be 38 bytes
      $endgroup$
      – DJMcMayhem
      40 mins ago



















    1












    $begingroup$


    Jelly, 7 bytes



    +,ạ5eo=


    Try it online!



    How it works



    +,ạ5eo=  Main link. Arguments: x, y (integers)

    + Yield x+y.
    ạ Yield |x-y|.
    , Pair; yield (x+y, |x-y|).
    5e Test fi 5 exists in the pair.
    = Test x and y for equality.
    o Logical OR.





    share|improve this answer









    $endgroup$





















      1












      $begingroup$


      Python 2, 30 bytes





      lambda a,b:a in(b,5-b,b-5,b+5)


      Try it online!



      One byte saved by Arnauld



      Three bytes saved by alephalpha





      share











      $endgroup$









      • 1




        $begingroup$
        lambda a,b:a in(b,5-b,b-5,b+5)
        $endgroup$
        – alephalpha
        4 mins ago



















      0












      $begingroup$


      PowerShell, 48 bytes





      param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x


      Try it online!



      Takes input $a and $b. Checks if 5 is -in the group $b-$a, $a-$b, or $a+$b, stores the first into $x, and -ors the -in check with !$x to check equality.






      share|improve this answer









      $endgroup$





















        0












        $begingroup$


        Japt, 14 bytes



        r¥ ª[Ux Ura]ø5


        Try it online!






        share|improve this answer









        $endgroup$





















          0












          $begingroup$


          Japt, 12 bytes



          ¶Vª(U-V a ¶5


          Very lazy, simply checks equal or absolute difference.



          Try it online!






          share|improve this answer









          $endgroup$









          • 2




            $begingroup$
            Welcome back! Unfortunately, this isn't checking for sum == 5
            $endgroup$
            – Oliver
            4 mins ago



















          0












          $begingroup$


          C (gcc), 41 36 bytes





          f(a,b){a=5==abs(a-b)||a+b==5||a==b;}


          Try it online!






          share|improve this answer









          $endgroup$





















            0












            $begingroup$


            Wolfram Language (Mathematica), 26 bytes



            !{#,5-#,#-5,#+5}~FreeQ~#2&


            Try it online!





            share









            $endgroup$





















              0












              $begingroup$

              Scala, 45 bytes





              def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b


              Try it online!





              share









              $endgroup$





















                0












                $begingroup$


                C# (.NET Core), 43, 48, 47 bytes



                EDIT: Tried to use % and apparently forgot how to %. Thanks to Arnauld for pointing that out!



                EDIT2: AdmBorkBork with a -1 byte golf rearranging the parentheses to sit next to the return so no additional space is needed!





                (a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}


                Try it online!






                share|improve this answer











                $endgroup$













                • $begingroup$
                  Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
                  $endgroup$
                  – Destroigo
                  13 mins ago



















                0












                $begingroup$

                Japt, 13 12 bytes



                x ¥5|50sèUra


                Try it or run all test cases





                share









                $endgroup$





















                  0












                  $begingroup$


                  J, 12 bytes



                  1#.=+5=|@-,+


                  Try it online!



                  Explanation



                  This is equivalent to:



                  1 #. = + 5 = |@- , +


                  This can be divided into the following fork chain:



                  (1 #. (= + (5 = (|@- , +))))


                  Or, visualized using 5!:4<'f':



                    ┌─ 1                   
                  ├─ #.
                  ──┤ ┌─ =
                  │ ├─ +
                  └────┤ ┌─ 5
                  │ ├─ =
                  └───┤ ┌─ |
                  │ ┌─ @ ─┴─ -
                  └───┼─ ,
                  └─ +


                  Annotated:



                    ┌─ 1                                       noun 1
                  ├─ #. base conversion (summation - any?)
                  ──┤ ┌─ = equality
                  │ ├─ + added to (boolean or)
                  └────┤ ┌─ 5 noun 5
                  │ ├─ = is equal to
                  └───┤ ┌─ | absolute value |
                  │ ┌─ @ ─┴─ - (of) subtraction |
                  └───┼─ , paired with |
                  └─ + subtraction | any of these?




                  share









                  $endgroup$





















                    0












                    $begingroup$


                    Dyalog APL, 9 bytes





                    =∨5∊+,∘|-


                    Try it online!






                    share|improve this answer











                    $endgroup$





















                      0












                      $begingroup$


                      Tcl, 58 bytes



                      proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}


                      Try it online!





                      share











                      $endgroup$













                        Your Answer





                        StackExchange.ifUsing("editor", function () {
                        return StackExchange.using("mathjaxEditing", function () {
                        StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                        StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                        });
                        });
                        }, "mathjax-editing");

                        StackExchange.ifUsing("editor", function () {
                        StackExchange.using("externalEditor", function () {
                        StackExchange.using("snippets", function () {
                        StackExchange.snippets.init();
                        });
                        });
                        }, "code-snippets");

                        StackExchange.ready(function() {
                        var channelOptions = {
                        tags: "".split(" "),
                        id: "200"
                        };
                        initTagRenderer("".split(" "), "".split(" "), channelOptions);

                        StackExchange.using("externalEditor", function() {
                        // Have to fire editor after snippets, if snippets enabled
                        if (StackExchange.settings.snippets.snippetsEnabled) {
                        StackExchange.using("snippets", function() {
                        createEditor();
                        });
                        }
                        else {
                        createEditor();
                        }
                        });

                        function createEditor() {
                        StackExchange.prepareEditor({
                        heartbeatType: 'answer',
                        autoActivateHeartbeat: false,
                        convertImagesToLinks: false,
                        noModals: true,
                        showLowRepImageUploadWarning: true,
                        reputationToPostImages: null,
                        bindNavPrevention: true,
                        postfix: "",
                        imageUploader: {
                        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                        allowUrls: true
                        },
                        onDemand: true,
                        discardSelector: ".discard-answer"
                        ,immediatelyShowMarkdownHelp:true
                        });


                        }
                        });






                        Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.










                        draft saved

                        draft discarded


















                        StackExchange.ready(
                        function () {
                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178792%2fequal-sum-or-difference%23new-answer', 'question_page');
                        }
                        );

                        Post as a guest















                        Required, but never shown

























                        15 Answers
                        15






                        active

                        oldest

                        votes








                        15 Answers
                        15






                        active

                        oldest

                        votes









                        active

                        oldest

                        votes






                        active

                        oldest

                        votes









                        4












                        $begingroup$

                        JavaScript (ES6), 28 bytes



                        Takes input as (a)(b). Returns $0$ or $1$.





                        a=>b=>a+b==5|!(a-=b)|a*a==25


                        Try it online!






                        share|improve this answer











                        $endgroup$


















                          4












                          $begingroup$

                          JavaScript (ES6), 28 bytes



                          Takes input as (a)(b). Returns $0$ or $1$.





                          a=>b=>a+b==5|!(a-=b)|a*a==25


                          Try it online!






                          share|improve this answer











                          $endgroup$
















                            4












                            4








                            4





                            $begingroup$

                            JavaScript (ES6), 28 bytes



                            Takes input as (a)(b). Returns $0$ or $1$.





                            a=>b=>a+b==5|!(a-=b)|a*a==25


                            Try it online!






                            share|improve this answer











                            $endgroup$



                            JavaScript (ES6), 28 bytes



                            Takes input as (a)(b). Returns $0$ or $1$.





                            a=>b=>a+b==5|!(a-=b)|a*a==25


                            Try it online!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 35 mins ago

























                            answered 48 mins ago









                            ArnauldArnauld

                            73.2k689307




                            73.2k689307























                                2












                                $begingroup$

                                Python 2, 40 bytes





                                lambda a,b:a+b==5 or abs(a-b)==5 or a==b


                                Try it online!






                                share|improve this answer









                                $endgroup$













                                • $begingroup$
                                  Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the 5s and the ors
                                  $endgroup$
                                  – ElPedro
                                  43 mins ago








                                • 1




                                  $begingroup$
                                  Actually, the TIO link could be 38 bytes
                                  $endgroup$
                                  – DJMcMayhem
                                  40 mins ago
















                                2












                                $begingroup$

                                Python 2, 40 bytes





                                lambda a,b:a+b==5 or abs(a-b)==5 or a==b


                                Try it online!






                                share|improve this answer









                                $endgroup$













                                • $begingroup$
                                  Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the 5s and the ors
                                  $endgroup$
                                  – ElPedro
                                  43 mins ago








                                • 1




                                  $begingroup$
                                  Actually, the TIO link could be 38 bytes
                                  $endgroup$
                                  – DJMcMayhem
                                  40 mins ago














                                2












                                2








                                2





                                $begingroup$

                                Python 2, 40 bytes





                                lambda a,b:a+b==5 or abs(a-b)==5 or a==b


                                Try it online!






                                share|improve this answer









                                $endgroup$



                                Python 2, 40 bytes





                                lambda a,b:a+b==5 or abs(a-b)==5 or a==b


                                Try it online!







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered 46 mins ago









                                fəˈnɛtɪkfəˈnɛtɪk

                                3,6331637




                                3,6331637












                                • $begingroup$
                                  Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the 5s and the ors
                                  $endgroup$
                                  – ElPedro
                                  43 mins ago








                                • 1




                                  $begingroup$
                                  Actually, the TIO link could be 38 bytes
                                  $endgroup$
                                  – DJMcMayhem
                                  40 mins ago


















                                • $begingroup$
                                  Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the 5s and the ors
                                  $endgroup$
                                  – ElPedro
                                  43 mins ago








                                • 1




                                  $begingroup$
                                  Actually, the TIO link could be 38 bytes
                                  $endgroup$
                                  – DJMcMayhem
                                  40 mins ago
















                                $begingroup$
                                Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the 5s and the ors
                                $endgroup$
                                – ElPedro
                                43 mins ago






                                $begingroup$
                                Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the 5s and the ors
                                $endgroup$
                                – ElPedro
                                43 mins ago






                                1




                                1




                                $begingroup$
                                Actually, the TIO link could be 38 bytes
                                $endgroup$
                                – DJMcMayhem
                                40 mins ago




                                $begingroup$
                                Actually, the TIO link could be 38 bytes
                                $endgroup$
                                – DJMcMayhem
                                40 mins ago











                                1












                                $begingroup$


                                Jelly, 7 bytes



                                +,ạ5eo=


                                Try it online!



                                How it works



                                +,ạ5eo=  Main link. Arguments: x, y (integers)

                                + Yield x+y.
                                ạ Yield |x-y|.
                                , Pair; yield (x+y, |x-y|).
                                5e Test fi 5 exists in the pair.
                                = Test x and y for equality.
                                o Logical OR.





                                share|improve this answer









                                $endgroup$


















                                  1












                                  $begingroup$


                                  Jelly, 7 bytes



                                  +,ạ5eo=


                                  Try it online!



                                  How it works



                                  +,ạ5eo=  Main link. Arguments: x, y (integers)

                                  + Yield x+y.
                                  ạ Yield |x-y|.
                                  , Pair; yield (x+y, |x-y|).
                                  5e Test fi 5 exists in the pair.
                                  = Test x and y for equality.
                                  o Logical OR.





                                  share|improve this answer









                                  $endgroup$
















                                    1












                                    1








                                    1





                                    $begingroup$


                                    Jelly, 7 bytes



                                    +,ạ5eo=


                                    Try it online!



                                    How it works



                                    +,ạ5eo=  Main link. Arguments: x, y (integers)

                                    + Yield x+y.
                                    ạ Yield |x-y|.
                                    , Pair; yield (x+y, |x-y|).
                                    5e Test fi 5 exists in the pair.
                                    = Test x and y for equality.
                                    o Logical OR.





                                    share|improve this answer









                                    $endgroup$




                                    Jelly, 7 bytes



                                    +,ạ5eo=


                                    Try it online!



                                    How it works



                                    +,ạ5eo=  Main link. Arguments: x, y (integers)

                                    + Yield x+y.
                                    ạ Yield |x-y|.
                                    , Pair; yield (x+y, |x-y|).
                                    5e Test fi 5 exists in the pair.
                                    = Test x and y for equality.
                                    o Logical OR.






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 32 mins ago









                                    DennisDennis

                                    187k32297736




                                    187k32297736























                                        1












                                        $begingroup$


                                        Python 2, 30 bytes





                                        lambda a,b:a in(b,5-b,b-5,b+5)


                                        Try it online!



                                        One byte saved by Arnauld



                                        Three bytes saved by alephalpha





                                        share











                                        $endgroup$









                                        • 1




                                          $begingroup$
                                          lambda a,b:a in(b,5-b,b-5,b+5)
                                          $endgroup$
                                          – alephalpha
                                          4 mins ago
















                                        1












                                        $begingroup$


                                        Python 2, 30 bytes





                                        lambda a,b:a in(b,5-b,b-5,b+5)


                                        Try it online!



                                        One byte saved by Arnauld



                                        Three bytes saved by alephalpha





                                        share











                                        $endgroup$









                                        • 1




                                          $begingroup$
                                          lambda a,b:a in(b,5-b,b-5,b+5)
                                          $endgroup$
                                          – alephalpha
                                          4 mins ago














                                        1












                                        1








                                        1





                                        $begingroup$


                                        Python 2, 30 bytes





                                        lambda a,b:a in(b,5-b,b-5,b+5)


                                        Try it online!



                                        One byte saved by Arnauld



                                        Three bytes saved by alephalpha





                                        share











                                        $endgroup$




                                        Python 2, 30 bytes





                                        lambda a,b:a in(b,5-b,b-5,b+5)


                                        Try it online!



                                        One byte saved by Arnauld



                                        Three bytes saved by alephalpha






                                        share













                                        share


                                        share








                                        edited 50 secs ago

























                                        answered 9 mins ago









                                        ArBoArBo

                                        1214




                                        1214








                                        • 1




                                          $begingroup$
                                          lambda a,b:a in(b,5-b,b-5,b+5)
                                          $endgroup$
                                          – alephalpha
                                          4 mins ago














                                        • 1




                                          $begingroup$
                                          lambda a,b:a in(b,5-b,b-5,b+5)
                                          $endgroup$
                                          – alephalpha
                                          4 mins ago








                                        1




                                        1




                                        $begingroup$
                                        lambda a,b:a in(b,5-b,b-5,b+5)
                                        $endgroup$
                                        – alephalpha
                                        4 mins ago




                                        $begingroup$
                                        lambda a,b:a in(b,5-b,b-5,b+5)
                                        $endgroup$
                                        – alephalpha
                                        4 mins ago











                                        0












                                        $begingroup$


                                        PowerShell, 48 bytes





                                        param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x


                                        Try it online!



                                        Takes input $a and $b. Checks if 5 is -in the group $b-$a, $a-$b, or $a+$b, stores the first into $x, and -ors the -in check with !$x to check equality.






                                        share|improve this answer









                                        $endgroup$


















                                          0












                                          $begingroup$


                                          PowerShell, 48 bytes





                                          param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x


                                          Try it online!



                                          Takes input $a and $b. Checks if 5 is -in the group $b-$a, $a-$b, or $a+$b, stores the first into $x, and -ors the -in check with !$x to check equality.






                                          share|improve this answer









                                          $endgroup$
















                                            0












                                            0








                                            0





                                            $begingroup$


                                            PowerShell, 48 bytes





                                            param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x


                                            Try it online!



                                            Takes input $a and $b. Checks if 5 is -in the group $b-$a, $a-$b, or $a+$b, stores the first into $x, and -ors the -in check with !$x to check equality.






                                            share|improve this answer









                                            $endgroup$




                                            PowerShell, 48 bytes





                                            param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x


                                            Try it online!



                                            Takes input $a and $b. Checks if 5 is -in the group $b-$a, $a-$b, or $a+$b, stores the first into $x, and -ors the -in check with !$x to check equality.







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered 26 mins ago









                                            AdmBorkBorkAdmBorkBork

                                            26.5k364229




                                            26.5k364229























                                                0












                                                $begingroup$


                                                Japt, 14 bytes



                                                r¥ ª[Ux Ura]ø5


                                                Try it online!






                                                share|improve this answer









                                                $endgroup$


















                                                  0












                                                  $begingroup$


                                                  Japt, 14 bytes



                                                  r¥ ª[Ux Ura]ø5


                                                  Try it online!






                                                  share|improve this answer









                                                  $endgroup$
















                                                    0












                                                    0








                                                    0





                                                    $begingroup$


                                                    Japt, 14 bytes



                                                    r¥ ª[Ux Ura]ø5


                                                    Try it online!






                                                    share|improve this answer









                                                    $endgroup$




                                                    Japt, 14 bytes



                                                    r¥ ª[Ux Ura]ø5


                                                    Try it online!







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered 22 mins ago









                                                    OliverOliver

                                                    4,7501831




                                                    4,7501831























                                                        0












                                                        $begingroup$


                                                        Japt, 12 bytes



                                                        ¶Vª(U-V a ¶5


                                                        Very lazy, simply checks equal or absolute difference.



                                                        Try it online!






                                                        share|improve this answer









                                                        $endgroup$









                                                        • 2




                                                          $begingroup$
                                                          Welcome back! Unfortunately, this isn't checking for sum == 5
                                                          $endgroup$
                                                          – Oliver
                                                          4 mins ago
















                                                        0












                                                        $begingroup$


                                                        Japt, 12 bytes



                                                        ¶Vª(U-V a ¶5


                                                        Very lazy, simply checks equal or absolute difference.



                                                        Try it online!






                                                        share|improve this answer









                                                        $endgroup$









                                                        • 2




                                                          $begingroup$
                                                          Welcome back! Unfortunately, this isn't checking for sum == 5
                                                          $endgroup$
                                                          – Oliver
                                                          4 mins ago














                                                        0












                                                        0








                                                        0





                                                        $begingroup$


                                                        Japt, 12 bytes



                                                        ¶Vª(U-V a ¶5


                                                        Very lazy, simply checks equal or absolute difference.



                                                        Try it online!






                                                        share|improve this answer









                                                        $endgroup$




                                                        Japt, 12 bytes



                                                        ¶Vª(U-V a ¶5


                                                        Very lazy, simply checks equal or absolute difference.



                                                        Try it online!







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered 19 mins ago









                                                        NitNit

                                                        1,92511419




                                                        1,92511419








                                                        • 2




                                                          $begingroup$
                                                          Welcome back! Unfortunately, this isn't checking for sum == 5
                                                          $endgroup$
                                                          – Oliver
                                                          4 mins ago














                                                        • 2




                                                          $begingroup$
                                                          Welcome back! Unfortunately, this isn't checking for sum == 5
                                                          $endgroup$
                                                          – Oliver
                                                          4 mins ago








                                                        2




                                                        2




                                                        $begingroup$
                                                        Welcome back! Unfortunately, this isn't checking for sum == 5
                                                        $endgroup$
                                                        – Oliver
                                                        4 mins ago




                                                        $begingroup$
                                                        Welcome back! Unfortunately, this isn't checking for sum == 5
                                                        $endgroup$
                                                        – Oliver
                                                        4 mins ago











                                                        0












                                                        $begingroup$


                                                        C (gcc), 41 36 bytes





                                                        f(a,b){a=5==abs(a-b)||a+b==5||a==b;}


                                                        Try it online!






                                                        share|improve this answer









                                                        $endgroup$


















                                                          0












                                                          $begingroup$


                                                          C (gcc), 41 36 bytes





                                                          f(a,b){a=5==abs(a-b)||a+b==5||a==b;}


                                                          Try it online!






                                                          share|improve this answer









                                                          $endgroup$
















                                                            0












                                                            0








                                                            0





                                                            $begingroup$


                                                            C (gcc), 41 36 bytes





                                                            f(a,b){a=5==abs(a-b)||a+b==5||a==b;}


                                                            Try it online!






                                                            share|improve this answer









                                                            $endgroup$




                                                            C (gcc), 41 36 bytes





                                                            f(a,b){a=5==abs(a-b)||a+b==5||a==b;}


                                                            Try it online!







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered 18 mins ago









                                                            cleblanccleblanc

                                                            3,180316




                                                            3,180316























                                                                0












                                                                $begingroup$


                                                                Wolfram Language (Mathematica), 26 bytes



                                                                !{#,5-#,#-5,#+5}~FreeQ~#2&


                                                                Try it online!





                                                                share









                                                                $endgroup$


















                                                                  0












                                                                  $begingroup$


                                                                  Wolfram Language (Mathematica), 26 bytes



                                                                  !{#,5-#,#-5,#+5}~FreeQ~#2&


                                                                  Try it online!





                                                                  share









                                                                  $endgroup$
















                                                                    0












                                                                    0








                                                                    0





                                                                    $begingroup$


                                                                    Wolfram Language (Mathematica), 26 bytes



                                                                    !{#,5-#,#-5,#+5}~FreeQ~#2&


                                                                    Try it online!





                                                                    share









                                                                    $endgroup$




                                                                    Wolfram Language (Mathematica), 26 bytes



                                                                    !{#,5-#,#-5,#+5}~FreeQ~#2&


                                                                    Try it online!






                                                                    share











                                                                    share


                                                                    share










                                                                    answered 5 mins ago









                                                                    alephalphaalephalpha

                                                                    21.2k32991




                                                                    21.2k32991























                                                                        0












                                                                        $begingroup$

                                                                        Scala, 45 bytes





                                                                        def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b


                                                                        Try it online!





                                                                        share









                                                                        $endgroup$


















                                                                          0












                                                                          $begingroup$

                                                                          Scala, 45 bytes





                                                                          def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b


                                                                          Try it online!





                                                                          share









                                                                          $endgroup$
















                                                                            0












                                                                            0








                                                                            0





                                                                            $begingroup$

                                                                            Scala, 45 bytes





                                                                            def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b


                                                                            Try it online!





                                                                            share









                                                                            $endgroup$



                                                                            Scala, 45 bytes





                                                                            def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b


                                                                            Try it online!






                                                                            share











                                                                            share


                                                                            share










                                                                            answered 4 mins ago









                                                                            Xavier GuihotXavier Guihot

                                                                            1937




                                                                            1937























                                                                                0












                                                                                $begingroup$


                                                                                C# (.NET Core), 43, 48, 47 bytes



                                                                                EDIT: Tried to use % and apparently forgot how to %. Thanks to Arnauld for pointing that out!



                                                                                EDIT2: AdmBorkBork with a -1 byte golf rearranging the parentheses to sit next to the return so no additional space is needed!





                                                                                (a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}


                                                                                Try it online!






                                                                                share|improve this answer











                                                                                $endgroup$













                                                                                • $begingroup$
                                                                                  Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
                                                                                  $endgroup$
                                                                                  – Destroigo
                                                                                  13 mins ago
















                                                                                0












                                                                                $begingroup$


                                                                                C# (.NET Core), 43, 48, 47 bytes



                                                                                EDIT: Tried to use % and apparently forgot how to %. Thanks to Arnauld for pointing that out!



                                                                                EDIT2: AdmBorkBork with a -1 byte golf rearranging the parentheses to sit next to the return so no additional space is needed!





                                                                                (a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}


                                                                                Try it online!






                                                                                share|improve this answer











                                                                                $endgroup$













                                                                                • $begingroup$
                                                                                  Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
                                                                                  $endgroup$
                                                                                  – Destroigo
                                                                                  13 mins ago














                                                                                0












                                                                                0








                                                                                0





                                                                                $begingroup$


                                                                                C# (.NET Core), 43, 48, 47 bytes



                                                                                EDIT: Tried to use % and apparently forgot how to %. Thanks to Arnauld for pointing that out!



                                                                                EDIT2: AdmBorkBork with a -1 byte golf rearranging the parentheses to sit next to the return so no additional space is needed!





                                                                                (a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}


                                                                                Try it online!






                                                                                share|improve this answer











                                                                                $endgroup$




                                                                                C# (.NET Core), 43, 48, 47 bytes



                                                                                EDIT: Tried to use % and apparently forgot how to %. Thanks to Arnauld for pointing that out!



                                                                                EDIT2: AdmBorkBork with a -1 byte golf rearranging the parentheses to sit next to the return so no additional space is needed!





                                                                                (a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}


                                                                                Try it online!







                                                                                share|improve this answer














                                                                                share|improve this answer



                                                                                share|improve this answer








                                                                                edited 3 mins ago

























                                                                                answered 23 mins ago









                                                                                DestroigoDestroigo

                                                                                1515




                                                                                1515












                                                                                • $begingroup$
                                                                                  Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
                                                                                  $endgroup$
                                                                                  – Destroigo
                                                                                  13 mins ago


















                                                                                • $begingroup$
                                                                                  Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
                                                                                  $endgroup$
                                                                                  – Destroigo
                                                                                  13 mins ago
















                                                                                $begingroup$
                                                                                Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
                                                                                $endgroup$
                                                                                – Destroigo
                                                                                13 mins ago




                                                                                $begingroup$
                                                                                Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
                                                                                $endgroup$
                                                                                – Destroigo
                                                                                13 mins ago











                                                                                0












                                                                                $begingroup$

                                                                                Japt, 13 12 bytes



                                                                                x ¥5|50sèUra


                                                                                Try it or run all test cases





                                                                                share









                                                                                $endgroup$


















                                                                                  0












                                                                                  $begingroup$

                                                                                  Japt, 13 12 bytes



                                                                                  x ¥5|50sèUra


                                                                                  Try it or run all test cases





                                                                                  share









                                                                                  $endgroup$
















                                                                                    0












                                                                                    0








                                                                                    0





                                                                                    $begingroup$

                                                                                    Japt, 13 12 bytes



                                                                                    x ¥5|50sèUra


                                                                                    Try it or run all test cases





                                                                                    share









                                                                                    $endgroup$



                                                                                    Japt, 13 12 bytes



                                                                                    x ¥5|50sèUra


                                                                                    Try it or run all test cases






                                                                                    share











                                                                                    share


                                                                                    share










                                                                                    answered 2 mins ago









                                                                                    ShaggyShaggy

                                                                                    19.2k21666




                                                                                    19.2k21666























                                                                                        0












                                                                                        $begingroup$


                                                                                        J, 12 bytes



                                                                                        1#.=+5=|@-,+


                                                                                        Try it online!



                                                                                        Explanation



                                                                                        This is equivalent to:



                                                                                        1 #. = + 5 = |@- , +


                                                                                        This can be divided into the following fork chain:



                                                                                        (1 #. (= + (5 = (|@- , +))))


                                                                                        Or, visualized using 5!:4<'f':



                                                                                          ┌─ 1                   
                                                                                        ├─ #.
                                                                                        ──┤ ┌─ =
                                                                                        │ ├─ +
                                                                                        └────┤ ┌─ 5
                                                                                        │ ├─ =
                                                                                        └───┤ ┌─ |
                                                                                        │ ┌─ @ ─┴─ -
                                                                                        └───┼─ ,
                                                                                        └─ +


                                                                                        Annotated:



                                                                                          ┌─ 1                                       noun 1
                                                                                        ├─ #. base conversion (summation - any?)
                                                                                        ──┤ ┌─ = equality
                                                                                        │ ├─ + added to (boolean or)
                                                                                        └────┤ ┌─ 5 noun 5
                                                                                        │ ├─ = is equal to
                                                                                        └───┤ ┌─ | absolute value |
                                                                                        │ ┌─ @ ─┴─ - (of) subtraction |
                                                                                        └───┼─ , paired with |
                                                                                        └─ + subtraction | any of these?




                                                                                        share









                                                                                        $endgroup$


















                                                                                          0












                                                                                          $begingroup$


                                                                                          J, 12 bytes



                                                                                          1#.=+5=|@-,+


                                                                                          Try it online!



                                                                                          Explanation



                                                                                          This is equivalent to:



                                                                                          1 #. = + 5 = |@- , +


                                                                                          This can be divided into the following fork chain:



                                                                                          (1 #. (= + (5 = (|@- , +))))


                                                                                          Or, visualized using 5!:4<'f':



                                                                                            ┌─ 1                   
                                                                                          ├─ #.
                                                                                          ──┤ ┌─ =
                                                                                          │ ├─ +
                                                                                          └────┤ ┌─ 5
                                                                                          │ ├─ =
                                                                                          └───┤ ┌─ |
                                                                                          │ ┌─ @ ─┴─ -
                                                                                          └───┼─ ,
                                                                                          └─ +


                                                                                          Annotated:



                                                                                            ┌─ 1                                       noun 1
                                                                                          ├─ #. base conversion (summation - any?)
                                                                                          ──┤ ┌─ = equality
                                                                                          │ ├─ + added to (boolean or)
                                                                                          └────┤ ┌─ 5 noun 5
                                                                                          │ ├─ = is equal to
                                                                                          └───┤ ┌─ | absolute value |
                                                                                          │ ┌─ @ ─┴─ - (of) subtraction |
                                                                                          └───┼─ , paired with |
                                                                                          └─ + subtraction | any of these?




                                                                                          share









                                                                                          $endgroup$
















                                                                                            0












                                                                                            0








                                                                                            0





                                                                                            $begingroup$


                                                                                            J, 12 bytes



                                                                                            1#.=+5=|@-,+


                                                                                            Try it online!



                                                                                            Explanation



                                                                                            This is equivalent to:



                                                                                            1 #. = + 5 = |@- , +


                                                                                            This can be divided into the following fork chain:



                                                                                            (1 #. (= + (5 = (|@- , +))))


                                                                                            Or, visualized using 5!:4<'f':



                                                                                              ┌─ 1                   
                                                                                            ├─ #.
                                                                                            ──┤ ┌─ =
                                                                                            │ ├─ +
                                                                                            └────┤ ┌─ 5
                                                                                            │ ├─ =
                                                                                            └───┤ ┌─ |
                                                                                            │ ┌─ @ ─┴─ -
                                                                                            └───┼─ ,
                                                                                            └─ +


                                                                                            Annotated:



                                                                                              ┌─ 1                                       noun 1
                                                                                            ├─ #. base conversion (summation - any?)
                                                                                            ──┤ ┌─ = equality
                                                                                            │ ├─ + added to (boolean or)
                                                                                            └────┤ ┌─ 5 noun 5
                                                                                            │ ├─ = is equal to
                                                                                            └───┤ ┌─ | absolute value |
                                                                                            │ ┌─ @ ─┴─ - (of) subtraction |
                                                                                            └───┼─ , paired with |
                                                                                            └─ + subtraction | any of these?




                                                                                            share









                                                                                            $endgroup$




                                                                                            J, 12 bytes



                                                                                            1#.=+5=|@-,+


                                                                                            Try it online!



                                                                                            Explanation



                                                                                            This is equivalent to:



                                                                                            1 #. = + 5 = |@- , +


                                                                                            This can be divided into the following fork chain:



                                                                                            (1 #. (= + (5 = (|@- , +))))


                                                                                            Or, visualized using 5!:4<'f':



                                                                                              ┌─ 1                   
                                                                                            ├─ #.
                                                                                            ──┤ ┌─ =
                                                                                            │ ├─ +
                                                                                            └────┤ ┌─ 5
                                                                                            │ ├─ =
                                                                                            └───┤ ┌─ |
                                                                                            │ ┌─ @ ─┴─ -
                                                                                            └───┼─ ,
                                                                                            └─ +


                                                                                            Annotated:



                                                                                              ┌─ 1                                       noun 1
                                                                                            ├─ #. base conversion (summation - any?)
                                                                                            ──┤ ┌─ = equality
                                                                                            │ ├─ + added to (boolean or)
                                                                                            └────┤ ┌─ 5 noun 5
                                                                                            │ ├─ = is equal to
                                                                                            └───┤ ┌─ | absolute value |
                                                                                            │ ┌─ @ ─┴─ - (of) subtraction |
                                                                                            └───┼─ , paired with |
                                                                                            └─ + subtraction | any of these?





                                                                                            share











                                                                                            share


                                                                                            share










                                                                                            answered 2 mins ago









                                                                                            Conor O'BrienConor O'Brien

                                                                                            29.2k263162




                                                                                            29.2k263162























                                                                                                0












                                                                                                $begingroup$


                                                                                                Dyalog APL, 9 bytes





                                                                                                =∨5∊+,∘|-


                                                                                                Try it online!






                                                                                                share|improve this answer











                                                                                                $endgroup$


















                                                                                                  0












                                                                                                  $begingroup$


                                                                                                  Dyalog APL, 9 bytes





                                                                                                  =∨5∊+,∘|-


                                                                                                  Try it online!






                                                                                                  share|improve this answer











                                                                                                  $endgroup$
















                                                                                                    0












                                                                                                    0








                                                                                                    0





                                                                                                    $begingroup$


                                                                                                    Dyalog APL, 9 bytes





                                                                                                    =∨5∊+,∘|-


                                                                                                    Try it online!






                                                                                                    share|improve this answer











                                                                                                    $endgroup$




                                                                                                    Dyalog APL, 9 bytes





                                                                                                    =∨5∊+,∘|-


                                                                                                    Try it online!







                                                                                                    share|improve this answer














                                                                                                    share|improve this answer



                                                                                                    share|improve this answer








                                                                                                    edited 1 min ago

























                                                                                                    answered 16 mins ago









                                                                                                    dzaimadzaima

                                                                                                    14.5k21755




                                                                                                    14.5k21755























                                                                                                        0












                                                                                                        $begingroup$


                                                                                                        Tcl, 58 bytes



                                                                                                        proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}


                                                                                                        Try it online!





                                                                                                        share











                                                                                                        $endgroup$


















                                                                                                          0












                                                                                                          $begingroup$


                                                                                                          Tcl, 58 bytes



                                                                                                          proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}


                                                                                                          Try it online!





                                                                                                          share











                                                                                                          $endgroup$
















                                                                                                            0












                                                                                                            0








                                                                                                            0





                                                                                                            $begingroup$


                                                                                                            Tcl, 58 bytes



                                                                                                            proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}


                                                                                                            Try it online!





                                                                                                            share











                                                                                                            $endgroup$




                                                                                                            Tcl, 58 bytes



                                                                                                            proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}


                                                                                                            Try it online!






                                                                                                            share













                                                                                                            share


                                                                                                            share








                                                                                                            edited 23 secs ago

























                                                                                                            answered 6 mins ago









                                                                                                            sergiolsergiol

                                                                                                            2,5171925




                                                                                                            2,5171925






















                                                                                                                Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.










                                                                                                                draft saved

                                                                                                                draft discarded


















                                                                                                                Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.













                                                                                                                Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.












                                                                                                                Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.
















                                                                                                                If this is an answer to a challenge…




                                                                                                                • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                                • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                                  Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                                • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                                                More generally…




                                                                                                                • …Please make sure to answer the question and provide sufficient detail.


                                                                                                                • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                                                                                draft saved


                                                                                                                draft discarded














                                                                                                                StackExchange.ready(
                                                                                                                function () {
                                                                                                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178792%2fequal-sum-or-difference%23new-answer', 'question_page');
                                                                                                                }
                                                                                                                );

                                                                                                                Post as a guest















                                                                                                                Required, but never shown





















































                                                                                                                Required, but never shown














                                                                                                                Required, but never shown












                                                                                                                Required, but never shown







                                                                                                                Required, but never shown

































                                                                                                                Required, but never shown














                                                                                                                Required, but never shown












                                                                                                                Required, but never shown







                                                                                                                Required, but never shown







                                                                                                                Popular posts from this blog

                                                                                                                Magento 2 controller redirect on button click in phtml file

                                                                                                                Polycentropodidae