Find if a list is an ABC-triple












7














Three positive integers A, B, C are ABC-triple if they are coprime,
with A < B and satisfying the relation : A + B = C



Examples :





  • 1, 8, 9 is an ABC-triple since they are coprime, 1 < 8 and 1 + 8 = 9


  • 6, 8, 14 is not because they are not coprime


  • 7, 5, 12 is not because 7 > 5


You can see this Frits Beukers 2005 presentation for more details about ABC-triples.



Input/Output



Three integers, decimal written. May be separated values or
list. Output had to be a truthy/falsy value whether the three
integers are an ABC-triple.



Test cases



Each of the following lists should output a truthy value




[1, 8, 9]



[2, 3, 5]



[2, 6436341, 6436343]



[4, 121, 125]



[121, 48234375, 48234496]




Each of the following lists should output a falsy value




[1, 1, 2]



[1, 2, 5]



[1, 9, 8]



[4, 12872682, 12872686]



[6, 8, 14]



[7, 5, 12]




Rules



No particular rules!










share|improve this question
























  • Does the output have to be only one of two values, or can we output different truthy/falsy values for different inputs?
    – Luis Mendo
    1 hour ago










  • I think it should be consistent: your code have to output one kind of truthy/falsy values whatever the input. But the truthy/falsy couple can be what you want as far as it does the job: differentiate lists.
    – david
    1 hour ago












  • If we take the input as list of three values, does the input have to be in the order [A,B,C], or are we also allowed to take the input in the order [C,B,A] or [C,A,B]?
    – Kevin Cruijssen
    39 mins ago










  • You have to respect order since A < B is a criteria in the challenge.
    – david
    37 mins ago










  • @david A < B can still be respected when we take the input list in the order [C,A,B]. ;) But ok, perhaps it's indeed best to leave the input-order for lists-input as [A,B,C] to reduce confusion.
    – Kevin Cruijssen
    33 mins ago
















7














Three positive integers A, B, C are ABC-triple if they are coprime,
with A < B and satisfying the relation : A + B = C



Examples :





  • 1, 8, 9 is an ABC-triple since they are coprime, 1 < 8 and 1 + 8 = 9


  • 6, 8, 14 is not because they are not coprime


  • 7, 5, 12 is not because 7 > 5


You can see this Frits Beukers 2005 presentation for more details about ABC-triples.



Input/Output



Three integers, decimal written. May be separated values or
list. Output had to be a truthy/falsy value whether the three
integers are an ABC-triple.



Test cases



Each of the following lists should output a truthy value




[1, 8, 9]



[2, 3, 5]



[2, 6436341, 6436343]



[4, 121, 125]



[121, 48234375, 48234496]




Each of the following lists should output a falsy value




[1, 1, 2]



[1, 2, 5]



[1, 9, 8]



[4, 12872682, 12872686]



[6, 8, 14]



[7, 5, 12]




Rules



No particular rules!










share|improve this question
























  • Does the output have to be only one of two values, or can we output different truthy/falsy values for different inputs?
    – Luis Mendo
    1 hour ago










  • I think it should be consistent: your code have to output one kind of truthy/falsy values whatever the input. But the truthy/falsy couple can be what you want as far as it does the job: differentiate lists.
    – david
    1 hour ago












  • If we take the input as list of three values, does the input have to be in the order [A,B,C], or are we also allowed to take the input in the order [C,B,A] or [C,A,B]?
    – Kevin Cruijssen
    39 mins ago










  • You have to respect order since A < B is a criteria in the challenge.
    – david
    37 mins ago










  • @david A < B can still be respected when we take the input list in the order [C,A,B]. ;) But ok, perhaps it's indeed best to leave the input-order for lists-input as [A,B,C] to reduce confusion.
    – Kevin Cruijssen
    33 mins ago














7












7








7







Three positive integers A, B, C are ABC-triple if they are coprime,
with A < B and satisfying the relation : A + B = C



Examples :





  • 1, 8, 9 is an ABC-triple since they are coprime, 1 < 8 and 1 + 8 = 9


  • 6, 8, 14 is not because they are not coprime


  • 7, 5, 12 is not because 7 > 5


You can see this Frits Beukers 2005 presentation for more details about ABC-triples.



Input/Output



Three integers, decimal written. May be separated values or
list. Output had to be a truthy/falsy value whether the three
integers are an ABC-triple.



Test cases



Each of the following lists should output a truthy value




[1, 8, 9]



[2, 3, 5]



[2, 6436341, 6436343]



[4, 121, 125]



[121, 48234375, 48234496]




Each of the following lists should output a falsy value




[1, 1, 2]



[1, 2, 5]



[1, 9, 8]



[4, 12872682, 12872686]



[6, 8, 14]



[7, 5, 12]




Rules



No particular rules!










share|improve this question















Three positive integers A, B, C are ABC-triple if they are coprime,
with A < B and satisfying the relation : A + B = C



Examples :





  • 1, 8, 9 is an ABC-triple since they are coprime, 1 < 8 and 1 + 8 = 9


  • 6, 8, 14 is not because they are not coprime


  • 7, 5, 12 is not because 7 > 5


You can see this Frits Beukers 2005 presentation for more details about ABC-triples.



Input/Output



Three integers, decimal written. May be separated values or
list. Output had to be a truthy/falsy value whether the three
integers are an ABC-triple.



Test cases



Each of the following lists should output a truthy value




[1, 8, 9]



[2, 3, 5]



[2, 6436341, 6436343]



[4, 121, 125]



[121, 48234375, 48234496]




Each of the following lists should output a falsy value




[1, 1, 2]



[1, 2, 5]



[1, 9, 8]



[4, 12872682, 12872686]



[6, 8, 14]



[7, 5, 12]




Rules



No particular rules!







code-golf sequence decision-problem number-theory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Luis Mendo

74k886291




74k886291










asked 1 hour ago









david

16919




16919












  • Does the output have to be only one of two values, or can we output different truthy/falsy values for different inputs?
    – Luis Mendo
    1 hour ago










  • I think it should be consistent: your code have to output one kind of truthy/falsy values whatever the input. But the truthy/falsy couple can be what you want as far as it does the job: differentiate lists.
    – david
    1 hour ago












  • If we take the input as list of three values, does the input have to be in the order [A,B,C], or are we also allowed to take the input in the order [C,B,A] or [C,A,B]?
    – Kevin Cruijssen
    39 mins ago










  • You have to respect order since A < B is a criteria in the challenge.
    – david
    37 mins ago










  • @david A < B can still be respected when we take the input list in the order [C,A,B]. ;) But ok, perhaps it's indeed best to leave the input-order for lists-input as [A,B,C] to reduce confusion.
    – Kevin Cruijssen
    33 mins ago


















  • Does the output have to be only one of two values, or can we output different truthy/falsy values for different inputs?
    – Luis Mendo
    1 hour ago










  • I think it should be consistent: your code have to output one kind of truthy/falsy values whatever the input. But the truthy/falsy couple can be what you want as far as it does the job: differentiate lists.
    – david
    1 hour ago












  • If we take the input as list of three values, does the input have to be in the order [A,B,C], or are we also allowed to take the input in the order [C,B,A] or [C,A,B]?
    – Kevin Cruijssen
    39 mins ago










  • You have to respect order since A < B is a criteria in the challenge.
    – david
    37 mins ago










  • @david A < B can still be respected when we take the input list in the order [C,A,B]. ;) But ok, perhaps it's indeed best to leave the input-order for lists-input as [A,B,C] to reduce confusion.
    – Kevin Cruijssen
    33 mins ago
















Does the output have to be only one of two values, or can we output different truthy/falsy values for different inputs?
– Luis Mendo
1 hour ago




Does the output have to be only one of two values, or can we output different truthy/falsy values for different inputs?
– Luis Mendo
1 hour ago












I think it should be consistent: your code have to output one kind of truthy/falsy values whatever the input. But the truthy/falsy couple can be what you want as far as it does the job: differentiate lists.
– david
1 hour ago






I think it should be consistent: your code have to output one kind of truthy/falsy values whatever the input. But the truthy/falsy couple can be what you want as far as it does the job: differentiate lists.
– david
1 hour ago














If we take the input as list of three values, does the input have to be in the order [A,B,C], or are we also allowed to take the input in the order [C,B,A] or [C,A,B]?
– Kevin Cruijssen
39 mins ago




If we take the input as list of three values, does the input have to be in the order [A,B,C], or are we also allowed to take the input in the order [C,B,A] or [C,A,B]?
– Kevin Cruijssen
39 mins ago












You have to respect order since A < B is a criteria in the challenge.
– david
37 mins ago




You have to respect order since A < B is a criteria in the challenge.
– david
37 mins ago












@david A < B can still be respected when we take the input list in the order [C,A,B]. ;) But ok, perhaps it's indeed best to leave the input-order for lists-input as [A,B,C] to reduce confusion.
– Kevin Cruijssen
33 mins ago




@david A < B can still be respected when we take the input list in the order [C,A,B]. ;) But ok, perhaps it's indeed best to leave the input-order for lists-input as [A,B,C] to reduce confusion.
– Kevin Cruijssen
33 mins ago










8 Answers
8






active

oldest

votes


















3















Perl 6, 33 bytes





{(.sum==.[2]*2*[<] $_)==[gcd] $_}


Try it online!



Anonymous code block that takes a list of three numbers and returns True or False.



Explanation



{(.sum==.[2]*2*[<] $_)==[gcd] $_}
{ } # Anonymous code block
[gcd] $_ # Is the gcd of all the numbers
( )== # Equal to
.sum # Whether the sum of numbes
== # Is equal to
.[2]*2 # The last element doubled
*[<] $_ # And elements are in ascending order





share|improve this answer























  • 32 bytes
    – nwellnhof
    36 mins ago



















2















05AB1E, 12 11 bytes



`‹sÂÆ_s¿PΘ


Try it online!
or as a Test Suite



Explanation



`            # push values of input list separately to stack
# remove the top (last) value
‹ # is a < b ?
sÂÆ # reduce a reversed copy of the input by subtraction
_ # logically negate
s¿ # push the gcd of the input
P # product of the stack
Θ # is true ?





share|improve this answer























  • Nice answer! I like the reduce by subtraction on the reversed input you've used to check if A + B = C. Too bad there isn't an "are all values on the stack equal" single-byte builtin (we can use of course, but it's just as long as ). I've asked OP if it's allowed to take the input in the order [C,B,A], in which case it can be 10 bytes like this: ¦`›sÆ_I¿PΘ.
    – Kevin Cruijssen
    35 mins ago





















1















Python 2, 69 67 63 62 bytes





lambda a,b,c:(c-b==a<b)/gcd(gcd(a,b),c)
from fractions import*


Try it online!






Python 3, 58 bytes





lambda a,b,c:(c-b==a<b)==gcd(gcd(a,b),c)
from math import*


Try it online!






share|improve this answer























  • is the gcd in gcd trick valid? What if a is not coprime with c?
    – Jo King
    1 hour ago






  • 2




    @jo-king If p divides a and c, it should divide c-a so b.
    – david
    1 hour ago






  • 2




    @JoKing: It is in this case, but not in general (you can prove it via Bezout's identity).
    – BMO
    1 hour ago



















1














JavaScript (ES6), 54 bytes



Returns $0$ or $1$.





(a,b,c)=>(g=(x,y=a)=>y?g(y,x%y):x)(b)*g(c)==a<b&a+b==c


Try it online!



How?



The helper function $g(x)$ computes the GCD of $x$ and $a$. To test whether $a$, $b$ and $c$ are coprime, we test whether $g(b)g(c)=1$. The right part of the equality is replaced with the result of the condition $a<b$.






share|improve this answer































    1















    Haskell, 48 38 bytes





    -10 bytes due to TFeld's gcd trick!



    g [a,b,c]=a<b&&a+b==c&&gcd(gcd a b)c<2


    Try it online!



    Explanation



    The first two conditions a < b and a + b == c are obvious, the third uses TFeld's intuition:



    Let us write $d = gcd(a,b)$. With Bézout's identity we can write $d = U cdot a + V cdot b$ and similarly $e = gcd(d,c) = X cdot d + Y cdot c$.



    Since we know that $a + b = c$ we can substitute $c$ and $b$ in the above identities, yielding two equations only in $a,b$ and $a,c$ respectively. Since the $gcd$ is the smallest positive element satisfying Bézout's identity the above condition is sufficient.






    share|improve this answer































      1















      Jelly, 10 7 bytes



      :<ƝḋgƝe


      Try it online!



      How it works



      :<ƝḋgƝe  Main link. Argument: [a, b, c] (positive integers)

      <Ɲ Less than neighbors; yield [(a < b), (b < c)].
      : Integer division; yield [a : (a < b), b : (b < c), c].
      The quotient is +oo if the divisor is 0.
      gƝ GCD neighbors; yield [gcd(a, b), gcd(b, c)].
      ḋ Dot product; yield (a : (a < b) × gcd(a, b) + b : (b < c) × gcd(b, c)).
      e Check if the result exists in [a, b, c].





      share|improve this answer































        0















        Japt, 16 14 bytes



        <V&Näj ×&U+V¥W


        Try it






        share|improve this answer































          0















          J, 27 bytes



          (+/=2*{:)*({.<1{])*1=+./ .*


          Try it online!



          Inspired by Jo King's Perl solution






          share|improve this answer























            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
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178303%2ffind-if-a-list-is-an-abc-triple%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            8 Answers
            8






            active

            oldest

            votes








            8 Answers
            8






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3















            Perl 6, 33 bytes





            {(.sum==.[2]*2*[<] $_)==[gcd] $_}


            Try it online!



            Anonymous code block that takes a list of three numbers and returns True or False.



            Explanation



            {(.sum==.[2]*2*[<] $_)==[gcd] $_}
            { } # Anonymous code block
            [gcd] $_ # Is the gcd of all the numbers
            ( )== # Equal to
            .sum # Whether the sum of numbes
            == # Is equal to
            .[2]*2 # The last element doubled
            *[<] $_ # And elements are in ascending order





            share|improve this answer























            • 32 bytes
              – nwellnhof
              36 mins ago
















            3















            Perl 6, 33 bytes





            {(.sum==.[2]*2*[<] $_)==[gcd] $_}


            Try it online!



            Anonymous code block that takes a list of three numbers and returns True or False.



            Explanation



            {(.sum==.[2]*2*[<] $_)==[gcd] $_}
            { } # Anonymous code block
            [gcd] $_ # Is the gcd of all the numbers
            ( )== # Equal to
            .sum # Whether the sum of numbes
            == # Is equal to
            .[2]*2 # The last element doubled
            *[<] $_ # And elements are in ascending order





            share|improve this answer























            • 32 bytes
              – nwellnhof
              36 mins ago














            3












            3








            3







            Perl 6, 33 bytes





            {(.sum==.[2]*2*[<] $_)==[gcd] $_}


            Try it online!



            Anonymous code block that takes a list of three numbers and returns True or False.



            Explanation



            {(.sum==.[2]*2*[<] $_)==[gcd] $_}
            { } # Anonymous code block
            [gcd] $_ # Is the gcd of all the numbers
            ( )== # Equal to
            .sum # Whether the sum of numbes
            == # Is equal to
            .[2]*2 # The last element doubled
            *[<] $_ # And elements are in ascending order





            share|improve this answer















            Perl 6, 33 bytes





            {(.sum==.[2]*2*[<] $_)==[gcd] $_}


            Try it online!



            Anonymous code block that takes a list of three numbers and returns True or False.



            Explanation



            {(.sum==.[2]*2*[<] $_)==[gcd] $_}
            { } # Anonymous code block
            [gcd] $_ # Is the gcd of all the numbers
            ( )== # Equal to
            .sum # Whether the sum of numbes
            == # Is equal to
            .[2]*2 # The last element doubled
            *[<] $_ # And elements are in ascending order






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 1 hour ago

























            answered 1 hour ago









            Jo King

            20.8k247110




            20.8k247110












            • 32 bytes
              – nwellnhof
              36 mins ago


















            • 32 bytes
              – nwellnhof
              36 mins ago
















            32 bytes
            – nwellnhof
            36 mins ago




            32 bytes
            – nwellnhof
            36 mins ago











            2















            05AB1E, 12 11 bytes



            `‹sÂÆ_s¿PΘ


            Try it online!
            or as a Test Suite



            Explanation



            `            # push values of input list separately to stack
            # remove the top (last) value
            ‹ # is a < b ?
            sÂÆ # reduce a reversed copy of the input by subtraction
            _ # logically negate
            s¿ # push the gcd of the input
            P # product of the stack
            Θ # is true ?





            share|improve this answer























            • Nice answer! I like the reduce by subtraction on the reversed input you've used to check if A + B = C. Too bad there isn't an "are all values on the stack equal" single-byte builtin (we can use of course, but it's just as long as ). I've asked OP if it's allowed to take the input in the order [C,B,A], in which case it can be 10 bytes like this: ¦`›sÆ_I¿PΘ.
              – Kevin Cruijssen
              35 mins ago


















            2















            05AB1E, 12 11 bytes



            `‹sÂÆ_s¿PΘ


            Try it online!
            or as a Test Suite



            Explanation



            `            # push values of input list separately to stack
            # remove the top (last) value
            ‹ # is a < b ?
            sÂÆ # reduce a reversed copy of the input by subtraction
            _ # logically negate
            s¿ # push the gcd of the input
            P # product of the stack
            Θ # is true ?





            share|improve this answer























            • Nice answer! I like the reduce by subtraction on the reversed input you've used to check if A + B = C. Too bad there isn't an "are all values on the stack equal" single-byte builtin (we can use of course, but it's just as long as ). I've asked OP if it's allowed to take the input in the order [C,B,A], in which case it can be 10 bytes like this: ¦`›sÆ_I¿PΘ.
              – Kevin Cruijssen
              35 mins ago
















            2












            2








            2







            05AB1E, 12 11 bytes



            `‹sÂÆ_s¿PΘ


            Try it online!
            or as a Test Suite



            Explanation



            `            # push values of input list separately to stack
            # remove the top (last) value
            ‹ # is a < b ?
            sÂÆ # reduce a reversed copy of the input by subtraction
            _ # logically negate
            s¿ # push the gcd of the input
            P # product of the stack
            Θ # is true ?





            share|improve this answer















            05AB1E, 12 11 bytes



            `‹sÂÆ_s¿PΘ


            Try it online!
            or as a Test Suite



            Explanation



            `            # push values of input list separately to stack
            # remove the top (last) value
            ‹ # is a < b ?
            sÂÆ # reduce a reversed copy of the input by subtraction
            _ # logically negate
            s¿ # push the gcd of the input
            P # product of the stack
            Θ # is true ?






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 52 mins ago

























            answered 1 hour ago









            Emigna

            45.4k432138




            45.4k432138












            • Nice answer! I like the reduce by subtraction on the reversed input you've used to check if A + B = C. Too bad there isn't an "are all values on the stack equal" single-byte builtin (we can use of course, but it's just as long as ). I've asked OP if it's allowed to take the input in the order [C,B,A], in which case it can be 10 bytes like this: ¦`›sÆ_I¿PΘ.
              – Kevin Cruijssen
              35 mins ago




















            • Nice answer! I like the reduce by subtraction on the reversed input you've used to check if A + B = C. Too bad there isn't an "are all values on the stack equal" single-byte builtin (we can use of course, but it's just as long as ). I've asked OP if it's allowed to take the input in the order [C,B,A], in which case it can be 10 bytes like this: ¦`›sÆ_I¿PΘ.
              – Kevin Cruijssen
              35 mins ago


















            Nice answer! I like the reduce by subtraction on the reversed input you've used to check if A + B = C. Too bad there isn't an "are all values on the stack equal" single-byte builtin (we can use of course, but it's just as long as ). I've asked OP if it's allowed to take the input in the order [C,B,A], in which case it can be 10 bytes like this: ¦`›sÆ_I¿PΘ.
            – Kevin Cruijssen
            35 mins ago






            Nice answer! I like the reduce by subtraction on the reversed input you've used to check if A + B = C. Too bad there isn't an "are all values on the stack equal" single-byte builtin (we can use of course, but it's just as long as ). I've asked OP if it's allowed to take the input in the order [C,B,A], in which case it can be 10 bytes like this: ¦`›sÆ_I¿PΘ.
            – Kevin Cruijssen
            35 mins ago













            1















            Python 2, 69 67 63 62 bytes





            lambda a,b,c:(c-b==a<b)/gcd(gcd(a,b),c)
            from fractions import*


            Try it online!






            Python 3, 58 bytes





            lambda a,b,c:(c-b==a<b)==gcd(gcd(a,b),c)
            from math import*


            Try it online!






            share|improve this answer























            • is the gcd in gcd trick valid? What if a is not coprime with c?
              – Jo King
              1 hour ago






            • 2




              @jo-king If p divides a and c, it should divide c-a so b.
              – david
              1 hour ago






            • 2




              @JoKing: It is in this case, but not in general (you can prove it via Bezout's identity).
              – BMO
              1 hour ago
















            1















            Python 2, 69 67 63 62 bytes





            lambda a,b,c:(c-b==a<b)/gcd(gcd(a,b),c)
            from fractions import*


            Try it online!






            Python 3, 58 bytes





            lambda a,b,c:(c-b==a<b)==gcd(gcd(a,b),c)
            from math import*


            Try it online!






            share|improve this answer























            • is the gcd in gcd trick valid? What if a is not coprime with c?
              – Jo King
              1 hour ago






            • 2




              @jo-king If p divides a and c, it should divide c-a so b.
              – david
              1 hour ago






            • 2




              @JoKing: It is in this case, but not in general (you can prove it via Bezout's identity).
              – BMO
              1 hour ago














            1












            1








            1







            Python 2, 69 67 63 62 bytes





            lambda a,b,c:(c-b==a<b)/gcd(gcd(a,b),c)
            from fractions import*


            Try it online!






            Python 3, 58 bytes





            lambda a,b,c:(c-b==a<b)==gcd(gcd(a,b),c)
            from math import*


            Try it online!






            share|improve this answer















            Python 2, 69 67 63 62 bytes





            lambda a,b,c:(c-b==a<b)/gcd(gcd(a,b),c)
            from fractions import*


            Try it online!






            Python 3, 58 bytes





            lambda a,b,c:(c-b==a<b)==gcd(gcd(a,b),c)
            from math import*


            Try it online!







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 49 mins ago

























            answered 1 hour ago









            TFeld

            14.2k21240




            14.2k21240












            • is the gcd in gcd trick valid? What if a is not coprime with c?
              – Jo King
              1 hour ago






            • 2




              @jo-king If p divides a and c, it should divide c-a so b.
              – david
              1 hour ago






            • 2




              @JoKing: It is in this case, but not in general (you can prove it via Bezout's identity).
              – BMO
              1 hour ago


















            • is the gcd in gcd trick valid? What if a is not coprime with c?
              – Jo King
              1 hour ago






            • 2




              @jo-king If p divides a and c, it should divide c-a so b.
              – david
              1 hour ago






            • 2




              @JoKing: It is in this case, but not in general (you can prove it via Bezout's identity).
              – BMO
              1 hour ago
















            is the gcd in gcd trick valid? What if a is not coprime with c?
            – Jo King
            1 hour ago




            is the gcd in gcd trick valid? What if a is not coprime with c?
            – Jo King
            1 hour ago




            2




            2




            @jo-king If p divides a and c, it should divide c-a so b.
            – david
            1 hour ago




            @jo-king If p divides a and c, it should divide c-a so b.
            – david
            1 hour ago




            2




            2




            @JoKing: It is in this case, but not in general (you can prove it via Bezout's identity).
            – BMO
            1 hour ago




            @JoKing: It is in this case, but not in general (you can prove it via Bezout's identity).
            – BMO
            1 hour ago











            1














            JavaScript (ES6), 54 bytes



            Returns $0$ or $1$.





            (a,b,c)=>(g=(x,y=a)=>y?g(y,x%y):x)(b)*g(c)==a<b&a+b==c


            Try it online!



            How?



            The helper function $g(x)$ computes the GCD of $x$ and $a$. To test whether $a$, $b$ and $c$ are coprime, we test whether $g(b)g(c)=1$. The right part of the equality is replaced with the result of the condition $a<b$.






            share|improve this answer




























              1














              JavaScript (ES6), 54 bytes



              Returns $0$ or $1$.





              (a,b,c)=>(g=(x,y=a)=>y?g(y,x%y):x)(b)*g(c)==a<b&a+b==c


              Try it online!



              How?



              The helper function $g(x)$ computes the GCD of $x$ and $a$. To test whether $a$, $b$ and $c$ are coprime, we test whether $g(b)g(c)=1$. The right part of the equality is replaced with the result of the condition $a<b$.






              share|improve this answer


























                1












                1








                1






                JavaScript (ES6), 54 bytes



                Returns $0$ or $1$.





                (a,b,c)=>(g=(x,y=a)=>y?g(y,x%y):x)(b)*g(c)==a<b&a+b==c


                Try it online!



                How?



                The helper function $g(x)$ computes the GCD of $x$ and $a$. To test whether $a$, $b$ and $c$ are coprime, we test whether $g(b)g(c)=1$. The right part of the equality is replaced with the result of the condition $a<b$.






                share|improve this answer














                JavaScript (ES6), 54 bytes



                Returns $0$ or $1$.





                (a,b,c)=>(g=(x,y=a)=>y?g(y,x%y):x)(b)*g(c)==a<b&a+b==c


                Try it online!



                How?



                The helper function $g(x)$ computes the GCD of $x$ and $a$. To test whether $a$, $b$ and $c$ are coprime, we test whether $g(b)g(c)=1$. The right part of the equality is replaced with the result of the condition $a<b$.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 40 mins ago

























                answered 1 hour ago









                Arnauld

                72.4k689305




                72.4k689305























                    1















                    Haskell, 48 38 bytes





                    -10 bytes due to TFeld's gcd trick!



                    g [a,b,c]=a<b&&a+b==c&&gcd(gcd a b)c<2


                    Try it online!



                    Explanation



                    The first two conditions a < b and a + b == c are obvious, the third uses TFeld's intuition:



                    Let us write $d = gcd(a,b)$. With Bézout's identity we can write $d = U cdot a + V cdot b$ and similarly $e = gcd(d,c) = X cdot d + Y cdot c$.



                    Since we know that $a + b = c$ we can substitute $c$ and $b$ in the above identities, yielding two equations only in $a,b$ and $a,c$ respectively. Since the $gcd$ is the smallest positive element satisfying Bézout's identity the above condition is sufficient.






                    share|improve this answer




























                      1















                      Haskell, 48 38 bytes





                      -10 bytes due to TFeld's gcd trick!



                      g [a,b,c]=a<b&&a+b==c&&gcd(gcd a b)c<2


                      Try it online!



                      Explanation



                      The first two conditions a < b and a + b == c are obvious, the third uses TFeld's intuition:



                      Let us write $d = gcd(a,b)$. With Bézout's identity we can write $d = U cdot a + V cdot b$ and similarly $e = gcd(d,c) = X cdot d + Y cdot c$.



                      Since we know that $a + b = c$ we can substitute $c$ and $b$ in the above identities, yielding two equations only in $a,b$ and $a,c$ respectively. Since the $gcd$ is the smallest positive element satisfying Bézout's identity the above condition is sufficient.






                      share|improve this answer


























                        1












                        1








                        1







                        Haskell, 48 38 bytes





                        -10 bytes due to TFeld's gcd trick!



                        g [a,b,c]=a<b&&a+b==c&&gcd(gcd a b)c<2


                        Try it online!



                        Explanation



                        The first two conditions a < b and a + b == c are obvious, the third uses TFeld's intuition:



                        Let us write $d = gcd(a,b)$. With Bézout's identity we can write $d = U cdot a + V cdot b$ and similarly $e = gcd(d,c) = X cdot d + Y cdot c$.



                        Since we know that $a + b = c$ we can substitute $c$ and $b$ in the above identities, yielding two equations only in $a,b$ and $a,c$ respectively. Since the $gcd$ is the smallest positive element satisfying Bézout's identity the above condition is sufficient.






                        share|improve this answer















                        Haskell, 48 38 bytes





                        -10 bytes due to TFeld's gcd trick!



                        g [a,b,c]=a<b&&a+b==c&&gcd(gcd a b)c<2


                        Try it online!



                        Explanation



                        The first two conditions a < b and a + b == c are obvious, the third uses TFeld's intuition:



                        Let us write $d = gcd(a,b)$. With Bézout's identity we can write $d = U cdot a + V cdot b$ and similarly $e = gcd(d,c) = X cdot d + Y cdot c$.



                        Since we know that $a + b = c$ we can substitute $c$ and $b$ in the above identities, yielding two equations only in $a,b$ and $a,c$ respectively. Since the $gcd$ is the smallest positive element satisfying Bézout's identity the above condition is sufficient.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited 39 mins ago

























                        answered 1 hour ago









                        BMO

                        11.5k22186




                        11.5k22186























                            1















                            Jelly, 10 7 bytes



                            :<ƝḋgƝe


                            Try it online!



                            How it works



                            :<ƝḋgƝe  Main link. Argument: [a, b, c] (positive integers)

                            <Ɲ Less than neighbors; yield [(a < b), (b < c)].
                            : Integer division; yield [a : (a < b), b : (b < c), c].
                            The quotient is +oo if the divisor is 0.
                            gƝ GCD neighbors; yield [gcd(a, b), gcd(b, c)].
                            ḋ Dot product; yield (a : (a < b) × gcd(a, b) + b : (b < c) × gcd(b, c)).
                            e Check if the result exists in [a, b, c].





                            share|improve this answer




























                              1















                              Jelly, 10 7 bytes



                              :<ƝḋgƝe


                              Try it online!



                              How it works



                              :<ƝḋgƝe  Main link. Argument: [a, b, c] (positive integers)

                              <Ɲ Less than neighbors; yield [(a < b), (b < c)].
                              : Integer division; yield [a : (a < b), b : (b < c), c].
                              The quotient is +oo if the divisor is 0.
                              gƝ GCD neighbors; yield [gcd(a, b), gcd(b, c)].
                              ḋ Dot product; yield (a : (a < b) × gcd(a, b) + b : (b < c) × gcd(b, c)).
                              e Check if the result exists in [a, b, c].





                              share|improve this answer


























                                1












                                1








                                1







                                Jelly, 10 7 bytes



                                :<ƝḋgƝe


                                Try it online!



                                How it works



                                :<ƝḋgƝe  Main link. Argument: [a, b, c] (positive integers)

                                <Ɲ Less than neighbors; yield [(a < b), (b < c)].
                                : Integer division; yield [a : (a < b), b : (b < c), c].
                                The quotient is +oo if the divisor is 0.
                                gƝ GCD neighbors; yield [gcd(a, b), gcd(b, c)].
                                ḋ Dot product; yield (a : (a < b) × gcd(a, b) + b : (b < c) × gcd(b, c)).
                                e Check if the result exists in [a, b, c].





                                share|improve this answer















                                Jelly, 10 7 bytes



                                :<ƝḋgƝe


                                Try it online!



                                How it works



                                :<ƝḋgƝe  Main link. Argument: [a, b, c] (positive integers)

                                <Ɲ Less than neighbors; yield [(a < b), (b < c)].
                                : Integer division; yield [a : (a < b), b : (b < c), c].
                                The quotient is +oo if the divisor is 0.
                                gƝ GCD neighbors; yield [gcd(a, b), gcd(b, c)].
                                ḋ Dot product; yield (a : (a < b) × gcd(a, b) + b : (b < c) × gcd(b, c)).
                                e Check if the result exists in [a, b, c].






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 5 mins ago

























                                answered 25 mins ago









                                Dennis

                                186k32296735




                                186k32296735























                                    0















                                    Japt, 16 14 bytes



                                    <V&Näj ×&U+V¥W


                                    Try it






                                    share|improve this answer




























                                      0















                                      Japt, 16 14 bytes



                                      <V&Näj ×&U+V¥W


                                      Try it






                                      share|improve this answer


























                                        0












                                        0








                                        0







                                        Japt, 16 14 bytes



                                        <V&Näj ×&U+V¥W


                                        Try it






                                        share|improve this answer















                                        Japt, 16 14 bytes



                                        <V&Näj ×&U+V¥W


                                        Try it







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited 56 mins ago

























                                        answered 1 hour ago









                                        Shaggy

                                        18.9k21666




                                        18.9k21666























                                            0















                                            J, 27 bytes



                                            (+/=2*{:)*({.<1{])*1=+./ .*


                                            Try it online!



                                            Inspired by Jo King's Perl solution






                                            share|improve this answer




























                                              0















                                              J, 27 bytes



                                              (+/=2*{:)*({.<1{])*1=+./ .*


                                              Try it online!



                                              Inspired by Jo King's Perl solution






                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                J, 27 bytes



                                                (+/=2*{:)*({.<1{])*1=+./ .*


                                                Try it online!



                                                Inspired by Jo King's Perl solution






                                                share|improve this answer















                                                J, 27 bytes



                                                (+/=2*{:)*({.<1{])*1=+./ .*


                                                Try it online!



                                                Inspired by Jo King's Perl solution







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited 31 mins ago

























                                                answered 38 mins ago









                                                Galen Ivanov

                                                6,34711032




                                                6,34711032






























                                                    draft saved

                                                    draft discarded




















































                                                    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).






                                                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                    Please pay close attention to the following guidance:


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid



                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                    To learn more, see our tips on writing great answers.




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function () {
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178303%2ffind-if-a-list-is-an-abc-triple%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

                                                    Understanding the information contained in the Deep Space Network XML data?

                                                    Ross-on-Wye

                                                    Eastern Orthodox Church