The max() is not enough

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












Intro



A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?".



While we didn't find a way to do this within reasonable definitions of "a single command", I thought it might be a fun problem to golf.



 Challenge



"Return the largest of a list of integers if-and-only-if they are not all equal."



More specifically:



Given a string containing only a comma-separated list of integers:



  • If they are all equal, return/output nothing

  • Else, return/output the largest

Rules



  • The input must be a string containing only a comma-separated list of integers

  • The output must be either nothing (no output of any kind), or else the largest element from the input, represented as it is in the input

Entries may be a full program or just a function, provided you provide some way to test them!



Assumptions



  • Assume input list elements may be more than one digit but no larger than
    ( 232 − 1 )

  • Assume the input list has no more than a million elements

  • Assume the input will not include negative values

  • Assume the input will never be empty

For the avoidance of doubt, the explanation of the challenge given just after "More specifically" shall supersede the statement of the challenge above it ("Return the largest...").



 Examples



(1) All equal:



Input: 1,1
Output:


(2) Dissimilar:



Input: 1,2
Output: 2


(3) Zero!:



Input: 0,0,0,0,0,0,0,1,0,0
Output: 1


(4) Random:



Input: 7,3,8,4,8,3,9,4,6,1,3,7,5
Output: 9


(5) Larger numbers, larger list:



Input: 627,3894,863,5195,7789,5269,8887,3262,1448,3192
Output: 8887


Additional examples:



(6) All equal, larger list:



Input: 7,7,7,7,7,7,7,7,7
Output:


(7) All equal, larger list, larger numbers:



Input: 61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976
Output:


(8) Not equal, larger list, larger numbers:



Input: 96185,482754,96185,96185,96185,96185,96185,96185,7,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,961185,96185,96185,96185
Output: 961185 (sorry)


Scoring



This is code-golf, so the code with the shortest number of bytes wins!










share|improve this question

















  • 2




    Is it OK to throw an error when the list contains all equal values? And can we output a null value (such as None in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the input
    – DJMcMayhem♦
    1 hour ago







  • 2




    Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
    – Arnauld
    1 hour ago










  • I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
    – Shaggy
    29 mins ago










  • @Arnauld Please vote based on the challenge not on user that posted it.
    – W W
    29 mins ago














up vote
2
down vote

favorite












Intro



A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?".



While we didn't find a way to do this within reasonable definitions of "a single command", I thought it might be a fun problem to golf.



 Challenge



"Return the largest of a list of integers if-and-only-if they are not all equal."



More specifically:



Given a string containing only a comma-separated list of integers:



  • If they are all equal, return/output nothing

  • Else, return/output the largest

Rules



  • The input must be a string containing only a comma-separated list of integers

  • The output must be either nothing (no output of any kind), or else the largest element from the input, represented as it is in the input

Entries may be a full program or just a function, provided you provide some way to test them!



Assumptions



  • Assume input list elements may be more than one digit but no larger than
    ( 232 − 1 )

  • Assume the input list has no more than a million elements

  • Assume the input will not include negative values

  • Assume the input will never be empty

For the avoidance of doubt, the explanation of the challenge given just after "More specifically" shall supersede the statement of the challenge above it ("Return the largest...").



 Examples



(1) All equal:



Input: 1,1
Output:


(2) Dissimilar:



Input: 1,2
Output: 2


(3) Zero!:



Input: 0,0,0,0,0,0,0,1,0,0
Output: 1


(4) Random:



Input: 7,3,8,4,8,3,9,4,6,1,3,7,5
Output: 9


(5) Larger numbers, larger list:



Input: 627,3894,863,5195,7789,5269,8887,3262,1448,3192
Output: 8887


Additional examples:



(6) All equal, larger list:



Input: 7,7,7,7,7,7,7,7,7
Output:


(7) All equal, larger list, larger numbers:



Input: 61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976
Output:


(8) Not equal, larger list, larger numbers:



Input: 96185,482754,96185,96185,96185,96185,96185,96185,7,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,961185,96185,96185,96185
Output: 961185 (sorry)


Scoring



This is code-golf, so the code with the shortest number of bytes wins!










share|improve this question

















  • 2




    Is it OK to throw an error when the list contains all equal values? And can we output a null value (such as None in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the input
    – DJMcMayhem♦
    1 hour ago







  • 2




    Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
    – Arnauld
    1 hour ago










  • I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
    – Shaggy
    29 mins ago










  • @Arnauld Please vote based on the challenge not on user that posted it.
    – W W
    29 mins ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











Intro



A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?".



While we didn't find a way to do this within reasonable definitions of "a single command", I thought it might be a fun problem to golf.



 Challenge



"Return the largest of a list of integers if-and-only-if they are not all equal."



More specifically:



Given a string containing only a comma-separated list of integers:



  • If they are all equal, return/output nothing

  • Else, return/output the largest

Rules



  • The input must be a string containing only a comma-separated list of integers

  • The output must be either nothing (no output of any kind), or else the largest element from the input, represented as it is in the input

Entries may be a full program or just a function, provided you provide some way to test them!



Assumptions



  • Assume input list elements may be more than one digit but no larger than
    ( 232 − 1 )

  • Assume the input list has no more than a million elements

  • Assume the input will not include negative values

  • Assume the input will never be empty

For the avoidance of doubt, the explanation of the challenge given just after "More specifically" shall supersede the statement of the challenge above it ("Return the largest...").



 Examples



(1) All equal:



Input: 1,1
Output:


(2) Dissimilar:



Input: 1,2
Output: 2


(3) Zero!:



Input: 0,0,0,0,0,0,0,1,0,0
Output: 1


(4) Random:



Input: 7,3,8,4,8,3,9,4,6,1,3,7,5
Output: 9


(5) Larger numbers, larger list:



Input: 627,3894,863,5195,7789,5269,8887,3262,1448,3192
Output: 8887


Additional examples:



(6) All equal, larger list:



Input: 7,7,7,7,7,7,7,7,7
Output:


(7) All equal, larger list, larger numbers:



Input: 61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976
Output:


(8) Not equal, larger list, larger numbers:



Input: 96185,482754,96185,96185,96185,96185,96185,96185,7,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,961185,96185,96185,96185
Output: 961185 (sorry)


Scoring



This is code-golf, so the code with the shortest number of bytes wins!










share|improve this question













Intro



A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?".



While we didn't find a way to do this within reasonable definitions of "a single command", I thought it might be a fun problem to golf.



 Challenge



"Return the largest of a list of integers if-and-only-if they are not all equal."



More specifically:



Given a string containing only a comma-separated list of integers:



  • If they are all equal, return/output nothing

  • Else, return/output the largest

Rules



  • The input must be a string containing only a comma-separated list of integers

  • The output must be either nothing (no output of any kind), or else the largest element from the input, represented as it is in the input

Entries may be a full program or just a function, provided you provide some way to test them!



Assumptions



  • Assume input list elements may be more than one digit but no larger than
    ( 232 − 1 )

  • Assume the input list has no more than a million elements

  • Assume the input will not include negative values

  • Assume the input will never be empty

For the avoidance of doubt, the explanation of the challenge given just after "More specifically" shall supersede the statement of the challenge above it ("Return the largest...").



 Examples



(1) All equal:



Input: 1,1
Output:


(2) Dissimilar:



Input: 1,2
Output: 2


(3) Zero!:



Input: 0,0,0,0,0,0,0,1,0,0
Output: 1


(4) Random:



Input: 7,3,8,4,8,3,9,4,6,1,3,7,5
Output: 9


(5) Larger numbers, larger list:



Input: 627,3894,863,5195,7789,5269,8887,3262,1448,3192
Output: 8887


Additional examples:



(6) All equal, larger list:



Input: 7,7,7,7,7,7,7,7,7
Output:


(7) All equal, larger list, larger numbers:



Input: 61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976
Output:


(8) Not equal, larger list, larger numbers:



Input: 96185,482754,96185,96185,96185,96185,96185,96185,7,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,961185,96185,96185,96185
Output: 961185 (sorry)


Scoring



This is code-golf, so the code with the shortest number of bytes wins!







code-golf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









ElectricWarr

193




193







  • 2




    Is it OK to throw an error when the list contains all equal values? And can we output a null value (such as None in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the input
    – DJMcMayhem♦
    1 hour ago







  • 2




    Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
    – Arnauld
    1 hour ago










  • I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
    – Shaggy
    29 mins ago










  • @Arnauld Please vote based on the challenge not on user that posted it.
    – W W
    29 mins ago












  • 2




    Is it OK to throw an error when the list contains all equal values? And can we output a null value (such as None in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the input
    – DJMcMayhem♦
    1 hour ago







  • 2




    Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
    – Arnauld
    1 hour ago










  • I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
    – Shaggy
    29 mins ago










  • @Arnauld Please vote based on the challenge not on user that posted it.
    – W W
    29 mins ago







2




2




Is it OK to throw an error when the list contains all equal values? And can we output a null value (such as None in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the input
– DJMcMayhem♦
1 hour ago





Is it OK to throw an error when the list contains all equal values? And can we output a null value (such as None in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the input
– DJMcMayhem♦
1 hour ago





2




2




Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
– Arnauld
1 hour ago




Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
– Arnauld
1 hour ago












I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
– Shaggy
29 mins ago




I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
– Shaggy
29 mins ago












@Arnauld Please vote based on the challenge not on user that posted it.
– W W
29 mins ago




@Arnauld Please vote based on the challenge not on user that posted it.
– W W
29 mins ago










11 Answers
11






active

oldest

votes

















up vote
1
down vote














CJam, 16 13 bytes



q',/:iL|$1>W>


Try it online!






share|improve this answer





























    up vote
    1
    down vote














    Neim, 4 bytes



    𝐐𝐎Ξ𝐠


    Explanation:



     Ξ If
    𝐐 all elements are equal
    𝐎 not
    then
    𝐠 get greatest element


    Try it online!






    share|improve this answer




















    • Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
      – Shaggy
      27 mins ago

















    up vote
    1
    down vote














    Python 2, 42 bytes



    a=input();print('',max(a))[len(set(a))!=1]


    Try it online!



    This assumes that the input has at least 1 element.



    This is my first code golf. It could probably be improved ;P






    share|improve this answer










    New contributor




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
























      up vote
      0
      down vote














      JavaScript (Node.js), 53 bytes



      Does a function returning '' count as no output? Sure this can be improved upon...





      s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)


      Try it online!






      share|improve this answer
















      • 1




        A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/…
        – Shaggy
        20 mins ago










      • @Shaggy nice! I started off using Set but couldn't get it as short as that
        – Chris M
        16 mins ago

















      up vote
      0
      down vote














      R, 50 bytes





      x=scan();`if`(length(unique(x))==1,cat(""),max(x))


      Try it online!



      If the input HAS to be a string...83 bytes.



      x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))


      Try it online!






      share|improve this answer





























        up vote
        0
        down vote














        Python 2, 44 bytes





        k=eval(input())
        if~-len(set(k)):print max(k)


        Try it online!






        share|improve this answer



























          up vote
          0
          down vote














          Ohm v2, 9 bytes



          Ul1E?Oq¿↑


          Try it online!
          Explanation:



          Ul1E?Oq¿↑
          U Uniquify input
          l Get length
          1E Push whether length is equak to 1
          ?Oq If so immediately quit
          ¿↑ Else print maximum





          share|improve this answer



























            up vote
            0
            down vote














            Octave, 28 bytes



            Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.





            @(a)max(a)(1+all(a(1)==a):1)


            Try it online!






            share|improve this answer



























              up vote
              0
              down vote














              Perl 6, 26 23 bytes





              .max if .Set>1o*.EVAL


              Try it online!



              Returns an empty slip if everything is equal.






              share|improve this answer





























                up vote
                0
                down vote














                K4, 38 bytes



                $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]


                Test Cases:



                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
                ,4
                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
                q)
                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
                ,9
                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
                q)


                I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though



                Explanation



                $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
                ",":x //split string on commas
                7h$ //cast strings to long
                -48 //they'll be from ascii format, so compensate
                ?: //get distinct list
                t: //set list to variable t
                #: //get count of t
                1= //check if count t = 1
                $[expr;`True;`False] is the conditional format
                ;; //return nothing if true
                x@>xt //if false, sort t descending
                *: //return first value


                Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.



                EDIT: If the commas are a problem, it can be fixed with two more bytes:



                q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
                4
                ,/ //joins the single element lists into one


                Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.






                share|improve this answer





























                  up vote
                  0
                  down vote













                  Japt, 16 bytes



                  This would be 9 if not for the unnecessarily strict input format.



                  Assumes the string contains at least 2 integers.



                  q, mn
                  â ÊÉ?Urw:P


                  Try it






                  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',
                    convertImagesToLinks: false,
                    noModals: false,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: null,
                    bindNavPrevention: true,
                    postfix: "",
                    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%2f173458%2fthe-max-is-not-enough%23new-answer', 'question_page');

                    );

                    Post as a guest






























                    11 Answers
                    11






                    active

                    oldest

                    votes








                    11 Answers
                    11






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    1
                    down vote














                    CJam, 16 13 bytes



                    q',/:iL|$1>W>


                    Try it online!






                    share|improve this answer


























                      up vote
                      1
                      down vote














                      CJam, 16 13 bytes



                      q',/:iL|$1>W>


                      Try it online!






                      share|improve this answer
























                        up vote
                        1
                        down vote










                        up vote
                        1
                        down vote










                        CJam, 16 13 bytes



                        q',/:iL|$1>W>


                        Try it online!






                        share|improve this answer















                        CJam, 16 13 bytes



                        q',/:iL|$1>W>


                        Try it online!







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited 1 hour ago

























                        answered 1 hour ago









                        Esolanging Fruit

                        8,09932373




                        8,09932373




















                            up vote
                            1
                            down vote














                            Neim, 4 bytes



                            𝐐𝐎Ξ𝐠


                            Explanation:



                             Ξ If
                            𝐐 all elements are equal
                            𝐎 not
                            then
                            𝐠 get greatest element


                            Try it online!






                            share|improve this answer




















                            • Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
                              – Shaggy
                              27 mins ago














                            up vote
                            1
                            down vote














                            Neim, 4 bytes



                            𝐐𝐎Ξ𝐠


                            Explanation:



                             Ξ If
                            𝐐 all elements are equal
                            𝐎 not
                            then
                            𝐠 get greatest element


                            Try it online!






                            share|improve this answer




















                            • Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
                              – Shaggy
                              27 mins ago












                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote










                            Neim, 4 bytes



                            𝐐𝐎Ξ𝐠


                            Explanation:



                             Ξ If
                            𝐐 all elements are equal
                            𝐎 not
                            then
                            𝐠 get greatest element


                            Try it online!






                            share|improve this answer













                            Neim, 4 bytes



                            𝐐𝐎Ξ𝐠


                            Explanation:



                             Ξ If
                            𝐐 all elements are equal
                            𝐎 not
                            then
                            𝐠 get greatest element


                            Try it online!







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 1 hour ago









                            Okx

                            12k27100




                            12k27100











                            • Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
                              – Shaggy
                              27 mins ago
















                            • Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
                              – Shaggy
                              27 mins ago















                            Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
                            – Shaggy
                            27 mins ago




                            Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
                            – Shaggy
                            27 mins ago










                            up vote
                            1
                            down vote














                            Python 2, 42 bytes



                            a=input();print('',max(a))[len(set(a))!=1]


                            Try it online!



                            This assumes that the input has at least 1 element.



                            This is my first code golf. It could probably be improved ;P






                            share|improve this answer










                            New contributor




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





















                              up vote
                              1
                              down vote














                              Python 2, 42 bytes



                              a=input();print('',max(a))[len(set(a))!=1]


                              Try it online!



                              This assumes that the input has at least 1 element.



                              This is my first code golf. It could probably be improved ;P






                              share|improve this answer










                              New contributor




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



















                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote










                                Python 2, 42 bytes



                                a=input();print('',max(a))[len(set(a))!=1]


                                Try it online!



                                This assumes that the input has at least 1 element.



                                This is my first code golf. It could probably be improved ;P






                                share|improve this answer










                                New contributor




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










                                Python 2, 42 bytes



                                a=input();print('',max(a))[len(set(a))!=1]


                                Try it online!



                                This assumes that the input has at least 1 element.



                                This is my first code golf. It could probably be improved ;P







                                share|improve this answer










                                New contributor




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









                                share|improve this answer



                                share|improve this answer








                                edited 8 mins ago





















                                New contributor




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









                                answered 25 mins ago









                                Arnav Borborah

                                1114




                                1114




                                New contributor




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





                                New contributor





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






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




















                                    up vote
                                    0
                                    down vote














                                    JavaScript (Node.js), 53 bytes



                                    Does a function returning '' count as no output? Sure this can be improved upon...





                                    s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)


                                    Try it online!






                                    share|improve this answer
















                                    • 1




                                      A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/…
                                      – Shaggy
                                      20 mins ago










                                    • @Shaggy nice! I started off using Set but couldn't get it as short as that
                                      – Chris M
                                      16 mins ago














                                    up vote
                                    0
                                    down vote














                                    JavaScript (Node.js), 53 bytes



                                    Does a function returning '' count as no output? Sure this can be improved upon...





                                    s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)


                                    Try it online!






                                    share|improve this answer
















                                    • 1




                                      A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/…
                                      – Shaggy
                                      20 mins ago










                                    • @Shaggy nice! I started off using Set but couldn't get it as short as that
                                      – Chris M
                                      16 mins ago












                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote










                                    JavaScript (Node.js), 53 bytes



                                    Does a function returning '' count as no output? Sure this can be improved upon...





                                    s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)


                                    Try it online!






                                    share|improve this answer













                                    JavaScript (Node.js), 53 bytes



                                    Does a function returning '' count as no output? Sure this can be improved upon...





                                    s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)


                                    Try it online!







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 1 hour ago









                                    Chris M

                                    1615




                                    1615







                                    • 1




                                      A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/…
                                      – Shaggy
                                      20 mins ago










                                    • @Shaggy nice! I started off using Set but couldn't get it as short as that
                                      – Chris M
                                      16 mins ago












                                    • 1




                                      A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/…
                                      – Shaggy
                                      20 mins ago










                                    • @Shaggy nice! I started off using Set but couldn't get it as short as that
                                      – Chris M
                                      16 mins ago







                                    1




                                    1




                                    A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/…
                                    – Shaggy
                                    20 mins ago




                                    A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/…
                                    – Shaggy
                                    20 mins ago












                                    @Shaggy nice! I started off using Set but couldn't get it as short as that
                                    – Chris M
                                    16 mins ago




                                    @Shaggy nice! I started off using Set but couldn't get it as short as that
                                    – Chris M
                                    16 mins ago










                                    up vote
                                    0
                                    down vote














                                    R, 50 bytes





                                    x=scan();`if`(length(unique(x))==1,cat(""),max(x))


                                    Try it online!



                                    If the input HAS to be a string...83 bytes.



                                    x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))


                                    Try it online!






                                    share|improve this answer


























                                      up vote
                                      0
                                      down vote














                                      R, 50 bytes





                                      x=scan();`if`(length(unique(x))==1,cat(""),max(x))


                                      Try it online!



                                      If the input HAS to be a string...83 bytes.



                                      x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))


                                      Try it online!






                                      share|improve this answer
























                                        up vote
                                        0
                                        down vote










                                        up vote
                                        0
                                        down vote










                                        R, 50 bytes





                                        x=scan();`if`(length(unique(x))==1,cat(""),max(x))


                                        Try it online!



                                        If the input HAS to be a string...83 bytes.



                                        x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))


                                        Try it online!






                                        share|improve this answer















                                        R, 50 bytes





                                        x=scan();`if`(length(unique(x))==1,cat(""),max(x))


                                        Try it online!



                                        If the input HAS to be a string...83 bytes.



                                        x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))


                                        Try it online!







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited 1 hour ago

























                                        answered 1 hour ago









                                        Robert S.

                                        47912




                                        47912




















                                            up vote
                                            0
                                            down vote














                                            Python 2, 44 bytes





                                            k=eval(input())
                                            if~-len(set(k)):print max(k)


                                            Try it online!






                                            share|improve this answer
























                                              up vote
                                              0
                                              down vote














                                              Python 2, 44 bytes





                                              k=eval(input())
                                              if~-len(set(k)):print max(k)


                                              Try it online!






                                              share|improve this answer






















                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote










                                                Python 2, 44 bytes





                                                k=eval(input())
                                                if~-len(set(k)):print max(k)


                                                Try it online!






                                                share|improve this answer













                                                Python 2, 44 bytes





                                                k=eval(input())
                                                if~-len(set(k)):print max(k)


                                                Try it online!







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 51 mins ago









                                                Chas Brown

                                                4,3111319




                                                4,3111319




















                                                    up vote
                                                    0
                                                    down vote














                                                    Ohm v2, 9 bytes



                                                    Ul1E?Oq¿↑


                                                    Try it online!
                                                    Explanation:



                                                    Ul1E?Oq¿↑
                                                    U Uniquify input
                                                    l Get length
                                                    1E Push whether length is equak to 1
                                                    ?Oq If so immediately quit
                                                    ¿↑ Else print maximum





                                                    share|improve this answer
























                                                      up vote
                                                      0
                                                      down vote














                                                      Ohm v2, 9 bytes



                                                      Ul1E?Oq¿↑


                                                      Try it online!
                                                      Explanation:



                                                      Ul1E?Oq¿↑
                                                      U Uniquify input
                                                      l Get length
                                                      1E Push whether length is equak to 1
                                                      ?Oq If so immediately quit
                                                      ¿↑ Else print maximum





                                                      share|improve this answer






















                                                        up vote
                                                        0
                                                        down vote










                                                        up vote
                                                        0
                                                        down vote










                                                        Ohm v2, 9 bytes



                                                        Ul1E?Oq¿↑


                                                        Try it online!
                                                        Explanation:



                                                        Ul1E?Oq¿↑
                                                        U Uniquify input
                                                        l Get length
                                                        1E Push whether length is equak to 1
                                                        ?Oq If so immediately quit
                                                        ¿↑ Else print maximum





                                                        share|improve this answer













                                                        Ohm v2, 9 bytes



                                                        Ul1E?Oq¿↑


                                                        Try it online!
                                                        Explanation:



                                                        Ul1E?Oq¿↑
                                                        U Uniquify input
                                                        l Get length
                                                        1E Push whether length is equak to 1
                                                        ?Oq If so immediately quit
                                                        ¿↑ Else print maximum






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered 49 mins ago









                                                        ThePlasmaRailgun

                                                        987




                                                        987




















                                                            up vote
                                                            0
                                                            down vote














                                                            Octave, 28 bytes



                                                            Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.





                                                            @(a)max(a)(1+all(a(1)==a):1)


                                                            Try it online!






                                                            share|improve this answer
























                                                              up vote
                                                              0
                                                              down vote














                                                              Octave, 28 bytes



                                                              Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.





                                                              @(a)max(a)(1+all(a(1)==a):1)


                                                              Try it online!






                                                              share|improve this answer






















                                                                up vote
                                                                0
                                                                down vote










                                                                up vote
                                                                0
                                                                down vote










                                                                Octave, 28 bytes



                                                                Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.





                                                                @(a)max(a)(1+all(a(1)==a):1)


                                                                Try it online!






                                                                share|improve this answer













                                                                Octave, 28 bytes



                                                                Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.





                                                                @(a)max(a)(1+all(a(1)==a):1)


                                                                Try it online!







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered 45 mins ago









                                                                flawr

                                                                25.8k562178




                                                                25.8k562178




















                                                                    up vote
                                                                    0
                                                                    down vote














                                                                    Perl 6, 26 23 bytes





                                                                    .max if .Set>1o*.EVAL


                                                                    Try it online!



                                                                    Returns an empty slip if everything is equal.






                                                                    share|improve this answer


























                                                                      up vote
                                                                      0
                                                                      down vote














                                                                      Perl 6, 26 23 bytes





                                                                      .max if .Set>1o*.EVAL


                                                                      Try it online!



                                                                      Returns an empty slip if everything is equal.






                                                                      share|improve this answer
























                                                                        up vote
                                                                        0
                                                                        down vote










                                                                        up vote
                                                                        0
                                                                        down vote










                                                                        Perl 6, 26 23 bytes





                                                                        .max if .Set>1o*.EVAL


                                                                        Try it online!



                                                                        Returns an empty slip if everything is equal.






                                                                        share|improve this answer















                                                                        Perl 6, 26 23 bytes





                                                                        .max if .Set>1o*.EVAL


                                                                        Try it online!



                                                                        Returns an empty slip if everything is equal.







                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited 42 mins ago

























                                                                        answered 1 hour ago









                                                                        Jo King

                                                                        16.9k24193




                                                                        16.9k24193




















                                                                            up vote
                                                                            0
                                                                            down vote














                                                                            K4, 38 bytes



                                                                            $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]


                                                                            Test Cases:



                                                                            q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
                                                                            ,4
                                                                            q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
                                                                            q)
                                                                            q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
                                                                            ,9
                                                                            q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
                                                                            q)


                                                                            I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though



                                                                            Explanation



                                                                            $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
                                                                            ",":x //split string on commas
                                                                            7h$ //cast strings to long
                                                                            -48 //they'll be from ascii format, so compensate
                                                                            ?: //get distinct list
                                                                            t: //set list to variable t
                                                                            #: //get count of t
                                                                            1= //check if count t = 1
                                                                            $[expr;`True;`False] is the conditional format
                                                                            ;; //return nothing if true
                                                                            x@>xt //if false, sort t descending
                                                                            *: //return first value


                                                                            Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.



                                                                            EDIT: If the commas are a problem, it can be fixed with two more bytes:



                                                                            q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
                                                                            4
                                                                            ,/ //joins the single element lists into one


                                                                            Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.






                                                                            share|improve this answer


























                                                                              up vote
                                                                              0
                                                                              down vote














                                                                              K4, 38 bytes



                                                                              $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]


                                                                              Test Cases:



                                                                              q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
                                                                              ,4
                                                                              q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
                                                                              q)
                                                                              q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
                                                                              ,9
                                                                              q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
                                                                              q)


                                                                              I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though



                                                                              Explanation



                                                                              $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
                                                                              ",":x //split string on commas
                                                                              7h$ //cast strings to long
                                                                              -48 //they'll be from ascii format, so compensate
                                                                              ?: //get distinct list
                                                                              t: //set list to variable t
                                                                              #: //get count of t
                                                                              1= //check if count t = 1
                                                                              $[expr;`True;`False] is the conditional format
                                                                              ;; //return nothing if true
                                                                              x@>xt //if false, sort t descending
                                                                              *: //return first value


                                                                              Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.



                                                                              EDIT: If the commas are a problem, it can be fixed with two more bytes:



                                                                              q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
                                                                              4
                                                                              ,/ //joins the single element lists into one


                                                                              Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.






                                                                              share|improve this answer
























                                                                                up vote
                                                                                0
                                                                                down vote










                                                                                up vote
                                                                                0
                                                                                down vote










                                                                                K4, 38 bytes



                                                                                $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]


                                                                                Test Cases:



                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
                                                                                ,4
                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
                                                                                q)
                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
                                                                                ,9
                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
                                                                                q)


                                                                                I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though



                                                                                Explanation



                                                                                $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
                                                                                ",":x //split string on commas
                                                                                7h$ //cast strings to long
                                                                                -48 //they'll be from ascii format, so compensate
                                                                                ?: //get distinct list
                                                                                t: //set list to variable t
                                                                                #: //get count of t
                                                                                1= //check if count t = 1
                                                                                $[expr;`True;`False] is the conditional format
                                                                                ;; //return nothing if true
                                                                                x@>xt //if false, sort t descending
                                                                                *: //return first value


                                                                                Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.



                                                                                EDIT: If the commas are a problem, it can be fixed with two more bytes:



                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
                                                                                4
                                                                                ,/ //joins the single element lists into one


                                                                                Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.






                                                                                share|improve this answer















                                                                                K4, 38 bytes



                                                                                $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]


                                                                                Test Cases:



                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
                                                                                ,4
                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
                                                                                q)
                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
                                                                                ,9
                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
                                                                                q)


                                                                                I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though



                                                                                Explanation



                                                                                $[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
                                                                                ",":x //split string on commas
                                                                                7h$ //cast strings to long
                                                                                -48 //they'll be from ascii format, so compensate
                                                                                ?: //get distinct list
                                                                                t: //set list to variable t
                                                                                #: //get count of t
                                                                                1= //check if count t = 1
                                                                                $[expr;`True;`False] is the conditional format
                                                                                ;; //return nothing if true
                                                                                x@>xt //if false, sort t descending
                                                                                *: //return first value


                                                                                Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.



                                                                                EDIT: If the commas are a problem, it can be fixed with two more bytes:



                                                                                q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
                                                                                4
                                                                                ,/ //joins the single element lists into one


                                                                                Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.







                                                                                share|improve this answer














                                                                                share|improve this answer



                                                                                share|improve this answer








                                                                                edited 19 mins ago

























                                                                                answered 48 mins ago









                                                                                Thaufeki

                                                                                1015




                                                                                1015




















                                                                                    up vote
                                                                                    0
                                                                                    down vote













                                                                                    Japt, 16 bytes



                                                                                    This would be 9 if not for the unnecessarily strict input format.



                                                                                    Assumes the string contains at least 2 integers.



                                                                                    q, mn
                                                                                    â ÊÉ?Urw:P


                                                                                    Try it






                                                                                    share|improve this answer
























                                                                                      up vote
                                                                                      0
                                                                                      down vote













                                                                                      Japt, 16 bytes



                                                                                      This would be 9 if not for the unnecessarily strict input format.



                                                                                      Assumes the string contains at least 2 integers.



                                                                                      q, mn
                                                                                      â ÊÉ?Urw:P


                                                                                      Try it






                                                                                      share|improve this answer






















                                                                                        up vote
                                                                                        0
                                                                                        down vote










                                                                                        up vote
                                                                                        0
                                                                                        down vote









                                                                                        Japt, 16 bytes



                                                                                        This would be 9 if not for the unnecessarily strict input format.



                                                                                        Assumes the string contains at least 2 integers.



                                                                                        q, mn
                                                                                        â ÊÉ?Urw:P


                                                                                        Try it






                                                                                        share|improve this answer












                                                                                        Japt, 16 bytes



                                                                                        This would be 9 if not for the unnecessarily strict input format.



                                                                                        Assumes the string contains at least 2 integers.



                                                                                        q, mn
                                                                                        â ÊÉ?Urw:P


                                                                                        Try it







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered 10 mins ago









                                                                                        Shaggy

                                                                                        17k21662




                                                                                        17k21662



























                                                                                             

                                                                                            draft saved


                                                                                            draft discarded















































                                                                                             


                                                                                            draft saved


                                                                                            draft discarded














                                                                                            StackExchange.ready(
                                                                                            function ()
                                                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173458%2fthe-max-is-not-enough%23new-answer', 'question_page');

                                                                                            );

                                                                                            Post as a guest













































































                                                                                            Comments

                                                                                            Popular posts from this blog

                                                                                            Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                                                                            What does second last employer means? [closed]

                                                                                            One-line joke