Valid term from quadratic sequence?Fibonacci function or sequenceSylvester's sequenceThe Squaring SequenceYet Unused PairsThe lowest initial numbers in a Fibonacci-like sequenceReconstruct an arithmetic sequenceCollection from a sequence that constitute a perfect squareFind Integral Roots of A PolynomialGenerate lowest degree polynomial from sequenceThe Written Digits Sequence

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?

If I cast Expeditious Retreat, can I Dash as a bonus action on the same turn?

To string or not to string

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

Do I have a twin with permutated remainders?

Today is the Center

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

Fencing style for blades that can attack from a distance

Is a tag line useful on a cover?

What's the point of deactivating Num Lock on login screens?

Has the BBC provided arguments for saying Brexit being cancelled is unlikely?

Maximum likelihood parameters deviate from posterior distributions

How to find program name(s) of an installed package?

How much RAM could one put in a typical 80386 setup?

How do I create uniquely male characters?

Email Account under attack (really) - anything I can do?

Font hinting is lost in Chrome-like browsers (for some languages )

What would happen to a modern skyscraper if it rains micro blackholes?

Why do falling prices hurt debtors?

Why does Kotter return in Welcome Back Kotter?

What is the word for reserving something for yourself before others do?

Why doesn't H₄O²⁺ exist?



Valid term from quadratic sequence?


Fibonacci function or sequenceSylvester's sequenceThe Squaring SequenceYet Unused PairsThe lowest initial numbers in a Fibonacci-like sequenceReconstruct an arithmetic sequenceCollection from a sequence that constitute a perfect squareFind Integral Roots of A PolynomialGenerate lowest degree polynomial from sequenceThe Written Digits Sequence













10












$begingroup$


You are given four numbers. The first three are $a$, $b$, and $c$ respectively, for the sequence:



$$T_n=an^2+bn+c$$



You may take input of these four numbers in any way. The output should be one of two distinct outputs mentioned in your answer, one means that the fourth number is a term in the sequence (the above equation has at least one solution for $n$ which is an integer when $a$, $b$, $c$ and $T_n$ are substituted for the given values), the other means the opposite.



This is code golf, so the shortest answer in bytes wins. Your program should work for any input of $a, b, c, T_n$ where the numbers are negative or positive (or 0), decimal or integer. To avoid problems but keep some complexity, non-integers will always just end in $.5$. Standard loop-holes disallowed.



Test cases



a |b |c |T_n |Y/N
------------------------
1 |1 |1 |1 |Y #n=0
2 |3 |5 |2 |N
0.5 |1 |-2 |-0.5|Y #n=1
0.5 |1 |-2 |15.5|Y #n=5
0.5 |1 |-2 |3 |N
-3.5|2 |-6 |-934|Y #n=-16
0 |1 |4 |7 |Y #n=3
0 |3 |-1 |7 |N
0 |0 |0 |1 |N
0 |0 |6 |6 |Y #n=<anything>
4 |8 |5 |2 |N









share|improve this question











$endgroup$
















    10












    $begingroup$


    You are given four numbers. The first three are $a$, $b$, and $c$ respectively, for the sequence:



    $$T_n=an^2+bn+c$$



    You may take input of these four numbers in any way. The output should be one of two distinct outputs mentioned in your answer, one means that the fourth number is a term in the sequence (the above equation has at least one solution for $n$ which is an integer when $a$, $b$, $c$ and $T_n$ are substituted for the given values), the other means the opposite.



    This is code golf, so the shortest answer in bytes wins. Your program should work for any input of $a, b, c, T_n$ where the numbers are negative or positive (or 0), decimal or integer. To avoid problems but keep some complexity, non-integers will always just end in $.5$. Standard loop-holes disallowed.



    Test cases



    a |b |c |T_n |Y/N
    ------------------------
    1 |1 |1 |1 |Y #n=0
    2 |3 |5 |2 |N
    0.5 |1 |-2 |-0.5|Y #n=1
    0.5 |1 |-2 |15.5|Y #n=5
    0.5 |1 |-2 |3 |N
    -3.5|2 |-6 |-934|Y #n=-16
    0 |1 |4 |7 |Y #n=3
    0 |3 |-1 |7 |N
    0 |0 |0 |1 |N
    0 |0 |6 |6 |Y #n=<anything>
    4 |8 |5 |2 |N









    share|improve this question











    $endgroup$














      10












      10








      10


      0



      $begingroup$


      You are given four numbers. The first three are $a$, $b$, and $c$ respectively, for the sequence:



      $$T_n=an^2+bn+c$$



      You may take input of these four numbers in any way. The output should be one of two distinct outputs mentioned in your answer, one means that the fourth number is a term in the sequence (the above equation has at least one solution for $n$ which is an integer when $a$, $b$, $c$ and $T_n$ are substituted for the given values), the other means the opposite.



      This is code golf, so the shortest answer in bytes wins. Your program should work for any input of $a, b, c, T_n$ where the numbers are negative or positive (or 0), decimal or integer. To avoid problems but keep some complexity, non-integers will always just end in $.5$. Standard loop-holes disallowed.



      Test cases



      a |b |c |T_n |Y/N
      ------------------------
      1 |1 |1 |1 |Y #n=0
      2 |3 |5 |2 |N
      0.5 |1 |-2 |-0.5|Y #n=1
      0.5 |1 |-2 |15.5|Y #n=5
      0.5 |1 |-2 |3 |N
      -3.5|2 |-6 |-934|Y #n=-16
      0 |1 |4 |7 |Y #n=3
      0 |3 |-1 |7 |N
      0 |0 |0 |1 |N
      0 |0 |6 |6 |Y #n=<anything>
      4 |8 |5 |2 |N









      share|improve this question











      $endgroup$




      You are given four numbers. The first three are $a$, $b$, and $c$ respectively, for the sequence:



      $$T_n=an^2+bn+c$$



      You may take input of these four numbers in any way. The output should be one of two distinct outputs mentioned in your answer, one means that the fourth number is a term in the sequence (the above equation has at least one solution for $n$ which is an integer when $a$, $b$, $c$ and $T_n$ are substituted for the given values), the other means the opposite.



      This is code golf, so the shortest answer in bytes wins. Your program should work for any input of $a, b, c, T_n$ where the numbers are negative or positive (or 0), decimal or integer. To avoid problems but keep some complexity, non-integers will always just end in $.5$. Standard loop-holes disallowed.



      Test cases



      a |b |c |T_n |Y/N
      ------------------------
      1 |1 |1 |1 |Y #n=0
      2 |3 |5 |2 |N
      0.5 |1 |-2 |-0.5|Y #n=1
      0.5 |1 |-2 |15.5|Y #n=5
      0.5 |1 |-2 |3 |N
      -3.5|2 |-6 |-934|Y #n=-16
      0 |1 |4 |7 |Y #n=3
      0 |3 |-1 |7 |N
      0 |0 |0 |1 |N
      0 |0 |6 |6 |Y #n=<anything>
      4 |8 |5 |2 |N






      code-golf number decision-problem equation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago







      Artemis Fowl

















      asked Apr 3 at 14:19









      Artemis FowlArtemis Fowl

      2119




      2119




















          5 Answers
          5






          active

          oldest

          votes


















          6












          $begingroup$

          JavaScript (ES7), 70 bytes



          Returns a Boolean value.





          (a,b,c,t)=>(t-=c,(a*=2)?(x=(b*b+2*a*t)**.5-b)%a&&(x+b+b)%a:b?t%b:t)==0


          Try it online!



          How?



          For the sake of clarity, we define $d = T_n-c$. (The same variable $t$ is re-used to store this result in the JS code.)



          Case $aneq0$



          The equation really is quadratic:



          $$T_n=an^2+bn+c\
          an^2+bn-d=0$$



          With $a'=2a$, the discriminant is:



          $$Delta=b^2+2a'd$$



          and the roots are:



          $$n_0=frac-b-sqrtDeltaa'\
          n_1=frac-b+sqrtDeltaa'$$



          The equation admits an integer root if $sqrtDelta$ is an integer and either:



          $$beginalign&-b-sqrtDeltaequiv 0pmoda'\ text or &-b+sqrtDeltaequiv 0pmoda'endalign$$



          Case $a=0, bneq0$



          The equation is linear:



          $$T_n=bn+c\
          bn=d\
          n=fracdb$$



          It admits an integer root if $dequiv0pmod b$.



          Case $a=0, b=0$



          The equation is not depending on $n$ anymore:



          $$T_n=c\
          d=0$$






          share|improve this answer











          $endgroup$




















            4












            $begingroup$


            Jelly,  11  10 bytes



            _/Ær1Ẹ?%1Ạ


            A monadic Link which accepts a list of lists* [[c, b, a], [T_n]] and yields 0 if T_n is a valid solution or 1 if not.



            * admittedly taking a little liberty with "You may take input of these four numbers in any way".



            Try it online! Or see a test-suite.



            How?



            _/Ær1Ẹ?%1Ạ - Link: list of lists of integers, [[c, b, a], [T_n]]
            / - reduce by:
            _ - subtraction [c-T_n, b, a]
            ? - if...
            Ẹ - ...condition: any?
            Ær - ...then: roots of polynomial i.e. roots of a²x+bx+(c-T_n)=0
            1 - ...else: literal 1
            %1 - modulo 1 (vectorises) i.e. for each: keep any fractional part
            - note: (a+bi)%1 yields nan which is truthy
            Ạ - all? i.e. all had fractional parts?
            - note: all([]) yields 1



            If we could yield non-distinct results then _/Ær1Ẹ?ḞƑƇ would also work for 10 (it yields 1 when all values are solutions, otherwise a list of the distinct solutions and hence always an empty list when no solutions - this would also meet the standard Truthy vs Falsey definition)






            share|improve this answer











            $endgroup$








            • 2




              $begingroup$
              That input is perfectly fine.
              $endgroup$
              – Artemis Fowl
              Apr 3 at 18:21


















            1












            $begingroup$


            05AB1E, 35 bytes



            Æ©²Āi²4P³n+tÐdi(‚³-IJ·Ä%P}뮳Āi³%]_


            Port of @Arnauld's JavaScript answer, so make sure to upvote him!



            Takes the input in the format $[t,c], a, b$.



            Try it online



            Explanation:





            Æ # Reduce the (implicit) input-list by subtraction (`t-c`)
            © # Store this value in the register (without popping)
            ²Āi # If the second input `a` is not 0:
            ²4P # Calculate `(t-c)*a*4`
            ³n+ # Add the third input `b` squared to it: `(t-c)*a*4+b*b`
            t # Take the square-root of that
            # (NOTE: 05AB1E and JS behave differently for square-roots of
            # negative integers; JS produces NaN, whereas 05AB1E leaves the
            # integer unchanged, which is why we have the `di...}` here)
            Ð # Triplicate this square
            di # If the square is non-negative (>= 0):
            (‚ # Pair it with its negative
            ³- # Subtract the third input `b` from each
            Ä # Take the absolute value of both
            ²·Ä% # Modulo the absolute value of `a` doubled
            # (NOTE: 05AB1E and JS behave differently for negative modulos,
            # which is why we have the two `Ä` here)
            P # Then multiply both by taking the product
            } # And close the inner if-statement
            ë # Else (`a` is 0):
            ® # Push the `t-c` from the register
            ³Āi # If the third input `b` is not 0:
            ³% # Take modulo `b`
            ] # Close both if-else statements
            _ # And check if the result is 0
            # (which is output implicitly)





            share|improve this answer









            $endgroup$












            • $begingroup$
              Would Ų save some bytes? (Probably not since we later need to compute the square root anyway.)
              $endgroup$
              – Arnauld
              2 days ago











            • $begingroup$
              @Arnauld Unfortunately not for three reasons: 1. Ų with negative values somehow gives the value itself instead of 0.. 2. Ų with decimal values (even with .0) gives 0 instead of 1 whether they're a square or not (this is a bug which I will report to Adnan). 3. Even if both would have worked and -4.0 would result in 0 instead of -4.0 and 4.0 would result in 1 instead of 0, it would still be +2 bytes since we need the square-root and the triplicate would be separated duplicates: tÐdi vs DŲitD; or currently DÄïŲitD to fix the other two mentioned issues.
              $endgroup$
              – Kevin Cruijssen
              2 days ago






            • 1




              $begingroup$
              Besides, the results of Ų on negative inputs are inconsistent.
              $endgroup$
              – Arnauld
              2 days ago










            • $begingroup$
              @Arnauld Wth.. that's indeed pretty weird. And the legacy version even gives a different, just as weird result.. :S I've reported the bugs, including your test TIO to Adnan in the 05AB1E chat.
              $endgroup$
              – Kevin Cruijssen
              2 days ago



















            0












            $begingroup$


            Wolfram Language (Mathematica), 38 bytes



            Solve[n^2#+n#2+#3==#4,n,Integers]!=&


            Try it online!






            share|improve this answer









            $endgroup$




















              0












              $begingroup$


              Jelly, 15 bytes



              _3¦UÆr=Ḟ$;3ị=ɗẸ


              Try it online!



              Built-in helps here but doesn’t handle a=b=0 so this is handled specially.






              share|improve this answer











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



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182606%2fvalid-term-from-quadratic-sequence%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                6












                $begingroup$

                JavaScript (ES7), 70 bytes



                Returns a Boolean value.





                (a,b,c,t)=>(t-=c,(a*=2)?(x=(b*b+2*a*t)**.5-b)%a&&(x+b+b)%a:b?t%b:t)==0


                Try it online!



                How?



                For the sake of clarity, we define $d = T_n-c$. (The same variable $t$ is re-used to store this result in the JS code.)



                Case $aneq0$



                The equation really is quadratic:



                $$T_n=an^2+bn+c\
                an^2+bn-d=0$$



                With $a'=2a$, the discriminant is:



                $$Delta=b^2+2a'd$$



                and the roots are:



                $$n_0=frac-b-sqrtDeltaa'\
                n_1=frac-b+sqrtDeltaa'$$



                The equation admits an integer root if $sqrtDelta$ is an integer and either:



                $$beginalign&-b-sqrtDeltaequiv 0pmoda'\ text or &-b+sqrtDeltaequiv 0pmoda'endalign$$



                Case $a=0, bneq0$



                The equation is linear:



                $$T_n=bn+c\
                bn=d\
                n=fracdb$$



                It admits an integer root if $dequiv0pmod b$.



                Case $a=0, b=0$



                The equation is not depending on $n$ anymore:



                $$T_n=c\
                d=0$$






                share|improve this answer











                $endgroup$

















                  6












                  $begingroup$

                  JavaScript (ES7), 70 bytes



                  Returns a Boolean value.





                  (a,b,c,t)=>(t-=c,(a*=2)?(x=(b*b+2*a*t)**.5-b)%a&&(x+b+b)%a:b?t%b:t)==0


                  Try it online!



                  How?



                  For the sake of clarity, we define $d = T_n-c$. (The same variable $t$ is re-used to store this result in the JS code.)



                  Case $aneq0$



                  The equation really is quadratic:



                  $$T_n=an^2+bn+c\
                  an^2+bn-d=0$$



                  With $a'=2a$, the discriminant is:



                  $$Delta=b^2+2a'd$$



                  and the roots are:



                  $$n_0=frac-b-sqrtDeltaa'\
                  n_1=frac-b+sqrtDeltaa'$$



                  The equation admits an integer root if $sqrtDelta$ is an integer and either:



                  $$beginalign&-b-sqrtDeltaequiv 0pmoda'\ text or &-b+sqrtDeltaequiv 0pmoda'endalign$$



                  Case $a=0, bneq0$



                  The equation is linear:



                  $$T_n=bn+c\
                  bn=d\
                  n=fracdb$$



                  It admits an integer root if $dequiv0pmod b$.



                  Case $a=0, b=0$



                  The equation is not depending on $n$ anymore:



                  $$T_n=c\
                  d=0$$






                  share|improve this answer











                  $endgroup$















                    6












                    6








                    6





                    $begingroup$

                    JavaScript (ES7), 70 bytes



                    Returns a Boolean value.





                    (a,b,c,t)=>(t-=c,(a*=2)?(x=(b*b+2*a*t)**.5-b)%a&&(x+b+b)%a:b?t%b:t)==0


                    Try it online!



                    How?



                    For the sake of clarity, we define $d = T_n-c$. (The same variable $t$ is re-used to store this result in the JS code.)



                    Case $aneq0$



                    The equation really is quadratic:



                    $$T_n=an^2+bn+c\
                    an^2+bn-d=0$$



                    With $a'=2a$, the discriminant is:



                    $$Delta=b^2+2a'd$$



                    and the roots are:



                    $$n_0=frac-b-sqrtDeltaa'\
                    n_1=frac-b+sqrtDeltaa'$$



                    The equation admits an integer root if $sqrtDelta$ is an integer and either:



                    $$beginalign&-b-sqrtDeltaequiv 0pmoda'\ text or &-b+sqrtDeltaequiv 0pmoda'endalign$$



                    Case $a=0, bneq0$



                    The equation is linear:



                    $$T_n=bn+c\
                    bn=d\
                    n=fracdb$$



                    It admits an integer root if $dequiv0pmod b$.



                    Case $a=0, b=0$



                    The equation is not depending on $n$ anymore:



                    $$T_n=c\
                    d=0$$






                    share|improve this answer











                    $endgroup$



                    JavaScript (ES7), 70 bytes



                    Returns a Boolean value.





                    (a,b,c,t)=>(t-=c,(a*=2)?(x=(b*b+2*a*t)**.5-b)%a&&(x+b+b)%a:b?t%b:t)==0


                    Try it online!



                    How?



                    For the sake of clarity, we define $d = T_n-c$. (The same variable $t$ is re-used to store this result in the JS code.)



                    Case $aneq0$



                    The equation really is quadratic:



                    $$T_n=an^2+bn+c\
                    an^2+bn-d=0$$



                    With $a'=2a$, the discriminant is:



                    $$Delta=b^2+2a'd$$



                    and the roots are:



                    $$n_0=frac-b-sqrtDeltaa'\
                    n_1=frac-b+sqrtDeltaa'$$



                    The equation admits an integer root if $sqrtDelta$ is an integer and either:



                    $$beginalign&-b-sqrtDeltaequiv 0pmoda'\ text or &-b+sqrtDeltaequiv 0pmoda'endalign$$



                    Case $a=0, bneq0$



                    The equation is linear:



                    $$T_n=bn+c\
                    bn=d\
                    n=fracdb$$



                    It admits an integer root if $dequiv0pmod b$.



                    Case $a=0, b=0$



                    The equation is not depending on $n$ anymore:



                    $$T_n=c\
                    d=0$$







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 2 days ago

























                    answered Apr 3 at 14:37









                    ArnauldArnauld

                    80.4k797333




                    80.4k797333





















                        4












                        $begingroup$


                        Jelly,  11  10 bytes



                        _/Ær1Ẹ?%1Ạ


                        A monadic Link which accepts a list of lists* [[c, b, a], [T_n]] and yields 0 if T_n is a valid solution or 1 if not.



                        * admittedly taking a little liberty with "You may take input of these four numbers in any way".



                        Try it online! Or see a test-suite.



                        How?



                        _/Ær1Ẹ?%1Ạ - Link: list of lists of integers, [[c, b, a], [T_n]]
                        / - reduce by:
                        _ - subtraction [c-T_n, b, a]
                        ? - if...
                        Ẹ - ...condition: any?
                        Ær - ...then: roots of polynomial i.e. roots of a²x+bx+(c-T_n)=0
                        1 - ...else: literal 1
                        %1 - modulo 1 (vectorises) i.e. for each: keep any fractional part
                        - note: (a+bi)%1 yields nan which is truthy
                        Ạ - all? i.e. all had fractional parts?
                        - note: all([]) yields 1



                        If we could yield non-distinct results then _/Ær1Ẹ?ḞƑƇ would also work for 10 (it yields 1 when all values are solutions, otherwise a list of the distinct solutions and hence always an empty list when no solutions - this would also meet the standard Truthy vs Falsey definition)






                        share|improve this answer











                        $endgroup$








                        • 2




                          $begingroup$
                          That input is perfectly fine.
                          $endgroup$
                          – Artemis Fowl
                          Apr 3 at 18:21















                        4












                        $begingroup$


                        Jelly,  11  10 bytes



                        _/Ær1Ẹ?%1Ạ


                        A monadic Link which accepts a list of lists* [[c, b, a], [T_n]] and yields 0 if T_n is a valid solution or 1 if not.



                        * admittedly taking a little liberty with "You may take input of these four numbers in any way".



                        Try it online! Or see a test-suite.



                        How?



                        _/Ær1Ẹ?%1Ạ - Link: list of lists of integers, [[c, b, a], [T_n]]
                        / - reduce by:
                        _ - subtraction [c-T_n, b, a]
                        ? - if...
                        Ẹ - ...condition: any?
                        Ær - ...then: roots of polynomial i.e. roots of a²x+bx+(c-T_n)=0
                        1 - ...else: literal 1
                        %1 - modulo 1 (vectorises) i.e. for each: keep any fractional part
                        - note: (a+bi)%1 yields nan which is truthy
                        Ạ - all? i.e. all had fractional parts?
                        - note: all([]) yields 1



                        If we could yield non-distinct results then _/Ær1Ẹ?ḞƑƇ would also work for 10 (it yields 1 when all values are solutions, otherwise a list of the distinct solutions and hence always an empty list when no solutions - this would also meet the standard Truthy vs Falsey definition)






                        share|improve this answer











                        $endgroup$








                        • 2




                          $begingroup$
                          That input is perfectly fine.
                          $endgroup$
                          – Artemis Fowl
                          Apr 3 at 18:21













                        4












                        4








                        4





                        $begingroup$


                        Jelly,  11  10 bytes



                        _/Ær1Ẹ?%1Ạ


                        A monadic Link which accepts a list of lists* [[c, b, a], [T_n]] and yields 0 if T_n is a valid solution or 1 if not.



                        * admittedly taking a little liberty with "You may take input of these four numbers in any way".



                        Try it online! Or see a test-suite.



                        How?



                        _/Ær1Ẹ?%1Ạ - Link: list of lists of integers, [[c, b, a], [T_n]]
                        / - reduce by:
                        _ - subtraction [c-T_n, b, a]
                        ? - if...
                        Ẹ - ...condition: any?
                        Ær - ...then: roots of polynomial i.e. roots of a²x+bx+(c-T_n)=0
                        1 - ...else: literal 1
                        %1 - modulo 1 (vectorises) i.e. for each: keep any fractional part
                        - note: (a+bi)%1 yields nan which is truthy
                        Ạ - all? i.e. all had fractional parts?
                        - note: all([]) yields 1



                        If we could yield non-distinct results then _/Ær1Ẹ?ḞƑƇ would also work for 10 (it yields 1 when all values are solutions, otherwise a list of the distinct solutions and hence always an empty list when no solutions - this would also meet the standard Truthy vs Falsey definition)






                        share|improve this answer











                        $endgroup$




                        Jelly,  11  10 bytes



                        _/Ær1Ẹ?%1Ạ


                        A monadic Link which accepts a list of lists* [[c, b, a], [T_n]] and yields 0 if T_n is a valid solution or 1 if not.



                        * admittedly taking a little liberty with "You may take input of these four numbers in any way".



                        Try it online! Or see a test-suite.



                        How?



                        _/Ær1Ẹ?%1Ạ - Link: list of lists of integers, [[c, b, a], [T_n]]
                        / - reduce by:
                        _ - subtraction [c-T_n, b, a]
                        ? - if...
                        Ẹ - ...condition: any?
                        Ær - ...then: roots of polynomial i.e. roots of a²x+bx+(c-T_n)=0
                        1 - ...else: literal 1
                        %1 - modulo 1 (vectorises) i.e. for each: keep any fractional part
                        - note: (a+bi)%1 yields nan which is truthy
                        Ạ - all? i.e. all had fractional parts?
                        - note: all([]) yields 1



                        If we could yield non-distinct results then _/Ær1Ẹ?ḞƑƇ would also work for 10 (it yields 1 when all values are solutions, otherwise a list of the distinct solutions and hence always an empty list when no solutions - this would also meet the standard Truthy vs Falsey definition)







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Apr 3 at 19:00

























                        answered Apr 3 at 17:23









                        Jonathan AllanJonathan Allan

                        53.7k535173




                        53.7k535173







                        • 2




                          $begingroup$
                          That input is perfectly fine.
                          $endgroup$
                          – Artemis Fowl
                          Apr 3 at 18:21












                        • 2




                          $begingroup$
                          That input is perfectly fine.
                          $endgroup$
                          – Artemis Fowl
                          Apr 3 at 18:21







                        2




                        2




                        $begingroup$
                        That input is perfectly fine.
                        $endgroup$
                        – Artemis Fowl
                        Apr 3 at 18:21




                        $begingroup$
                        That input is perfectly fine.
                        $endgroup$
                        – Artemis Fowl
                        Apr 3 at 18:21











                        1












                        $begingroup$


                        05AB1E, 35 bytes



                        Æ©²Āi²4P³n+tÐdi(‚³-IJ·Ä%P}뮳Āi³%]_


                        Port of @Arnauld's JavaScript answer, so make sure to upvote him!



                        Takes the input in the format $[t,c], a, b$.



                        Try it online



                        Explanation:





                        Æ # Reduce the (implicit) input-list by subtraction (`t-c`)
                        © # Store this value in the register (without popping)
                        ²Āi # If the second input `a` is not 0:
                        ²4P # Calculate `(t-c)*a*4`
                        ³n+ # Add the third input `b` squared to it: `(t-c)*a*4+b*b`
                        t # Take the square-root of that
                        # (NOTE: 05AB1E and JS behave differently for square-roots of
                        # negative integers; JS produces NaN, whereas 05AB1E leaves the
                        # integer unchanged, which is why we have the `di...}` here)
                        Ð # Triplicate this square
                        di # If the square is non-negative (>= 0):
                        (‚ # Pair it with its negative
                        ³- # Subtract the third input `b` from each
                        Ä # Take the absolute value of both
                        ²·Ä% # Modulo the absolute value of `a` doubled
                        # (NOTE: 05AB1E and JS behave differently for negative modulos,
                        # which is why we have the two `Ä` here)
                        P # Then multiply both by taking the product
                        } # And close the inner if-statement
                        ë # Else (`a` is 0):
                        ® # Push the `t-c` from the register
                        ³Āi # If the third input `b` is not 0:
                        ³% # Take modulo `b`
                        ] # Close both if-else statements
                        _ # And check if the result is 0
                        # (which is output implicitly)





                        share|improve this answer









                        $endgroup$












                        • $begingroup$
                          Would Ų save some bytes? (Probably not since we later need to compute the square root anyway.)
                          $endgroup$
                          – Arnauld
                          2 days ago











                        • $begingroup$
                          @Arnauld Unfortunately not for three reasons: 1. Ų with negative values somehow gives the value itself instead of 0.. 2. Ų with decimal values (even with .0) gives 0 instead of 1 whether they're a square or not (this is a bug which I will report to Adnan). 3. Even if both would have worked and -4.0 would result in 0 instead of -4.0 and 4.0 would result in 1 instead of 0, it would still be +2 bytes since we need the square-root and the triplicate would be separated duplicates: tÐdi vs DŲitD; or currently DÄïŲitD to fix the other two mentioned issues.
                          $endgroup$
                          – Kevin Cruijssen
                          2 days ago






                        • 1




                          $begingroup$
                          Besides, the results of Ų on negative inputs are inconsistent.
                          $endgroup$
                          – Arnauld
                          2 days ago










                        • $begingroup$
                          @Arnauld Wth.. that's indeed pretty weird. And the legacy version even gives a different, just as weird result.. :S I've reported the bugs, including your test TIO to Adnan in the 05AB1E chat.
                          $endgroup$
                          – Kevin Cruijssen
                          2 days ago
















                        1












                        $begingroup$


                        05AB1E, 35 bytes



                        Æ©²Āi²4P³n+tÐdi(‚³-IJ·Ä%P}뮳Āi³%]_


                        Port of @Arnauld's JavaScript answer, so make sure to upvote him!



                        Takes the input in the format $[t,c], a, b$.



                        Try it online



                        Explanation:





                        Æ # Reduce the (implicit) input-list by subtraction (`t-c`)
                        © # Store this value in the register (without popping)
                        ²Āi # If the second input `a` is not 0:
                        ²4P # Calculate `(t-c)*a*4`
                        ³n+ # Add the third input `b` squared to it: `(t-c)*a*4+b*b`
                        t # Take the square-root of that
                        # (NOTE: 05AB1E and JS behave differently for square-roots of
                        # negative integers; JS produces NaN, whereas 05AB1E leaves the
                        # integer unchanged, which is why we have the `di...}` here)
                        Ð # Triplicate this square
                        di # If the square is non-negative (>= 0):
                        (‚ # Pair it with its negative
                        ³- # Subtract the third input `b` from each
                        Ä # Take the absolute value of both
                        ²·Ä% # Modulo the absolute value of `a` doubled
                        # (NOTE: 05AB1E and JS behave differently for negative modulos,
                        # which is why we have the two `Ä` here)
                        P # Then multiply both by taking the product
                        } # And close the inner if-statement
                        ë # Else (`a` is 0):
                        ® # Push the `t-c` from the register
                        ³Āi # If the third input `b` is not 0:
                        ³% # Take modulo `b`
                        ] # Close both if-else statements
                        _ # And check if the result is 0
                        # (which is output implicitly)





                        share|improve this answer









                        $endgroup$












                        • $begingroup$
                          Would Ų save some bytes? (Probably not since we later need to compute the square root anyway.)
                          $endgroup$
                          – Arnauld
                          2 days ago











                        • $begingroup$
                          @Arnauld Unfortunately not for three reasons: 1. Ų with negative values somehow gives the value itself instead of 0.. 2. Ų with decimal values (even with .0) gives 0 instead of 1 whether they're a square or not (this is a bug which I will report to Adnan). 3. Even if both would have worked and -4.0 would result in 0 instead of -4.0 and 4.0 would result in 1 instead of 0, it would still be +2 bytes since we need the square-root and the triplicate would be separated duplicates: tÐdi vs DŲitD; or currently DÄïŲitD to fix the other two mentioned issues.
                          $endgroup$
                          – Kevin Cruijssen
                          2 days ago






                        • 1




                          $begingroup$
                          Besides, the results of Ų on negative inputs are inconsistent.
                          $endgroup$
                          – Arnauld
                          2 days ago










                        • $begingroup$
                          @Arnauld Wth.. that's indeed pretty weird. And the legacy version even gives a different, just as weird result.. :S I've reported the bugs, including your test TIO to Adnan in the 05AB1E chat.
                          $endgroup$
                          – Kevin Cruijssen
                          2 days ago














                        1












                        1








                        1





                        $begingroup$


                        05AB1E, 35 bytes



                        Æ©²Āi²4P³n+tÐdi(‚³-IJ·Ä%P}뮳Āi³%]_


                        Port of @Arnauld's JavaScript answer, so make sure to upvote him!



                        Takes the input in the format $[t,c], a, b$.



                        Try it online



                        Explanation:





                        Æ # Reduce the (implicit) input-list by subtraction (`t-c`)
                        © # Store this value in the register (without popping)
                        ²Āi # If the second input `a` is not 0:
                        ²4P # Calculate `(t-c)*a*4`
                        ³n+ # Add the third input `b` squared to it: `(t-c)*a*4+b*b`
                        t # Take the square-root of that
                        # (NOTE: 05AB1E and JS behave differently for square-roots of
                        # negative integers; JS produces NaN, whereas 05AB1E leaves the
                        # integer unchanged, which is why we have the `di...}` here)
                        Ð # Triplicate this square
                        di # If the square is non-negative (>= 0):
                        (‚ # Pair it with its negative
                        ³- # Subtract the third input `b` from each
                        Ä # Take the absolute value of both
                        ²·Ä% # Modulo the absolute value of `a` doubled
                        # (NOTE: 05AB1E and JS behave differently for negative modulos,
                        # which is why we have the two `Ä` here)
                        P # Then multiply both by taking the product
                        } # And close the inner if-statement
                        ë # Else (`a` is 0):
                        ® # Push the `t-c` from the register
                        ³Āi # If the third input `b` is not 0:
                        ³% # Take modulo `b`
                        ] # Close both if-else statements
                        _ # And check if the result is 0
                        # (which is output implicitly)





                        share|improve this answer









                        $endgroup$




                        05AB1E, 35 bytes



                        Æ©²Āi²4P³n+tÐdi(‚³-IJ·Ä%P}뮳Āi³%]_


                        Port of @Arnauld's JavaScript answer, so make sure to upvote him!



                        Takes the input in the format $[t,c], a, b$.



                        Try it online



                        Explanation:





                        Æ # Reduce the (implicit) input-list by subtraction (`t-c`)
                        © # Store this value in the register (without popping)
                        ²Āi # If the second input `a` is not 0:
                        ²4P # Calculate `(t-c)*a*4`
                        ³n+ # Add the third input `b` squared to it: `(t-c)*a*4+b*b`
                        t # Take the square-root of that
                        # (NOTE: 05AB1E and JS behave differently for square-roots of
                        # negative integers; JS produces NaN, whereas 05AB1E leaves the
                        # integer unchanged, which is why we have the `di...}` here)
                        Ð # Triplicate this square
                        di # If the square is non-negative (>= 0):
                        (‚ # Pair it with its negative
                        ³- # Subtract the third input `b` from each
                        Ä # Take the absolute value of both
                        ²·Ä% # Modulo the absolute value of `a` doubled
                        # (NOTE: 05AB1E and JS behave differently for negative modulos,
                        # which is why we have the two `Ä` here)
                        P # Then multiply both by taking the product
                        } # And close the inner if-statement
                        ë # Else (`a` is 0):
                        ® # Push the `t-c` from the register
                        ³Āi # If the third input `b` is not 0:
                        ³% # Take modulo `b`
                        ] # Close both if-else statements
                        _ # And check if the result is 0
                        # (which is output implicitly)






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 2 days ago









                        Kevin CruijssenKevin Cruijssen

                        42.3k570217




                        42.3k570217











                        • $begingroup$
                          Would Ų save some bytes? (Probably not since we later need to compute the square root anyway.)
                          $endgroup$
                          – Arnauld
                          2 days ago











                        • $begingroup$
                          @Arnauld Unfortunately not for three reasons: 1. Ų with negative values somehow gives the value itself instead of 0.. 2. Ų with decimal values (even with .0) gives 0 instead of 1 whether they're a square or not (this is a bug which I will report to Adnan). 3. Even if both would have worked and -4.0 would result in 0 instead of -4.0 and 4.0 would result in 1 instead of 0, it would still be +2 bytes since we need the square-root and the triplicate would be separated duplicates: tÐdi vs DŲitD; or currently DÄïŲitD to fix the other two mentioned issues.
                          $endgroup$
                          – Kevin Cruijssen
                          2 days ago






                        • 1




                          $begingroup$
                          Besides, the results of Ų on negative inputs are inconsistent.
                          $endgroup$
                          – Arnauld
                          2 days ago










                        • $begingroup$
                          @Arnauld Wth.. that's indeed pretty weird. And the legacy version even gives a different, just as weird result.. :S I've reported the bugs, including your test TIO to Adnan in the 05AB1E chat.
                          $endgroup$
                          – Kevin Cruijssen
                          2 days ago

















                        • $begingroup$
                          Would Ų save some bytes? (Probably not since we later need to compute the square root anyway.)
                          $endgroup$
                          – Arnauld
                          2 days ago











                        • $begingroup$
                          @Arnauld Unfortunately not for three reasons: 1. Ų with negative values somehow gives the value itself instead of 0.. 2. Ų with decimal values (even with .0) gives 0 instead of 1 whether they're a square or not (this is a bug which I will report to Adnan). 3. Even if both would have worked and -4.0 would result in 0 instead of -4.0 and 4.0 would result in 1 instead of 0, it would still be +2 bytes since we need the square-root and the triplicate would be separated duplicates: tÐdi vs DŲitD; or currently DÄïŲitD to fix the other two mentioned issues.
                          $endgroup$
                          – Kevin Cruijssen
                          2 days ago






                        • 1




                          $begingroup$
                          Besides, the results of Ų on negative inputs are inconsistent.
                          $endgroup$
                          – Arnauld
                          2 days ago










                        • $begingroup$
                          @Arnauld Wth.. that's indeed pretty weird. And the legacy version even gives a different, just as weird result.. :S I've reported the bugs, including your test TIO to Adnan in the 05AB1E chat.
                          $endgroup$
                          – Kevin Cruijssen
                          2 days ago
















                        $begingroup$
                        Would Ų save some bytes? (Probably not since we later need to compute the square root anyway.)
                        $endgroup$
                        – Arnauld
                        2 days ago





                        $begingroup$
                        Would Ų save some bytes? (Probably not since we later need to compute the square root anyway.)
                        $endgroup$
                        – Arnauld
                        2 days ago













                        $begingroup$
                        @Arnauld Unfortunately not for three reasons: 1. Ų with negative values somehow gives the value itself instead of 0.. 2. Ų with decimal values (even with .0) gives 0 instead of 1 whether they're a square or not (this is a bug which I will report to Adnan). 3. Even if both would have worked and -4.0 would result in 0 instead of -4.0 and 4.0 would result in 1 instead of 0, it would still be +2 bytes since we need the square-root and the triplicate would be separated duplicates: tÐdi vs DŲitD; or currently DÄïŲitD to fix the other two mentioned issues.
                        $endgroup$
                        – Kevin Cruijssen
                        2 days ago




                        $begingroup$
                        @Arnauld Unfortunately not for three reasons: 1. Ų with negative values somehow gives the value itself instead of 0.. 2. Ų with decimal values (even with .0) gives 0 instead of 1 whether they're a square or not (this is a bug which I will report to Adnan). 3. Even if both would have worked and -4.0 would result in 0 instead of -4.0 and 4.0 would result in 1 instead of 0, it would still be +2 bytes since we need the square-root and the triplicate would be separated duplicates: tÐdi vs DŲitD; or currently DÄïŲitD to fix the other two mentioned issues.
                        $endgroup$
                        – Kevin Cruijssen
                        2 days ago




                        1




                        1




                        $begingroup$
                        Besides, the results of Ų on negative inputs are inconsistent.
                        $endgroup$
                        – Arnauld
                        2 days ago




                        $begingroup$
                        Besides, the results of Ų on negative inputs are inconsistent.
                        $endgroup$
                        – Arnauld
                        2 days ago












                        $begingroup$
                        @Arnauld Wth.. that's indeed pretty weird. And the legacy version even gives a different, just as weird result.. :S I've reported the bugs, including your test TIO to Adnan in the 05AB1E chat.
                        $endgroup$
                        – Kevin Cruijssen
                        2 days ago





                        $begingroup$
                        @Arnauld Wth.. that's indeed pretty weird. And the legacy version even gives a different, just as weird result.. :S I've reported the bugs, including your test TIO to Adnan in the 05AB1E chat.
                        $endgroup$
                        – Kevin Cruijssen
                        2 days ago












                        0












                        $begingroup$


                        Wolfram Language (Mathematica), 38 bytes



                        Solve[n^2#+n#2+#3==#4,n,Integers]!=&


                        Try it online!






                        share|improve this answer









                        $endgroup$

















                          0












                          $begingroup$


                          Wolfram Language (Mathematica), 38 bytes



                          Solve[n^2#+n#2+#3==#4,n,Integers]!=&


                          Try it online!






                          share|improve this answer









                          $endgroup$















                            0












                            0








                            0





                            $begingroup$


                            Wolfram Language (Mathematica), 38 bytes



                            Solve[n^2#+n#2+#3==#4,n,Integers]!=&


                            Try it online!






                            share|improve this answer









                            $endgroup$




                            Wolfram Language (Mathematica), 38 bytes



                            Solve[n^2#+n#2+#3==#4,n,Integers]!=&


                            Try it online!







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 3 at 21:33









                            J42161217J42161217

                            13.8k21253




                            13.8k21253





















                                0












                                $begingroup$


                                Jelly, 15 bytes



                                _3¦UÆr=Ḟ$;3ị=ɗẸ


                                Try it online!



                                Built-in helps here but doesn’t handle a=b=0 so this is handled specially.






                                share|improve this answer











                                $endgroup$

















                                  0












                                  $begingroup$


                                  Jelly, 15 bytes



                                  _3¦UÆr=Ḟ$;3ị=ɗẸ


                                  Try it online!



                                  Built-in helps here but doesn’t handle a=b=0 so this is handled specially.






                                  share|improve this answer











                                  $endgroup$















                                    0












                                    0








                                    0





                                    $begingroup$


                                    Jelly, 15 bytes



                                    _3¦UÆr=Ḟ$;3ị=ɗẸ


                                    Try it online!



                                    Built-in helps here but doesn’t handle a=b=0 so this is handled specially.






                                    share|improve this answer











                                    $endgroup$




                                    Jelly, 15 bytes



                                    _3¦UÆr=Ḟ$;3ị=ɗẸ


                                    Try it online!



                                    Built-in helps here but doesn’t handle a=b=0 so this is handled specially.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited 2 days ago

























                                    answered Apr 3 at 16:46









                                    Nick KennedyNick Kennedy

                                    1,32649




                                    1,32649



























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




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182606%2fvalid-term-from-quadratic-sequence%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

                                        RemoteApp sporadic failureWindows 2008 RemoteAPP client disconnects within a matter of minutesWhat is the minimum version of RDP supported by Server 2012 RDS?How to configure a Remoteapp server to increase stabilityMicrosoft RemoteApp Active SessionRDWeb TS connection broken for some users post RemoteApp certificate changeRemote Desktop Licensing, RemoteAPPRDS 2012 R2 some users are not able to logon after changed date and time on Connection BrokersWhat happens during Remote Desktop logon, and is there any logging?After installing RDS on WinServer 2016 I still can only connect with two users?RD Connection via RDGW to Session host is not connecting

                                        How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

                                        Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos