Sort by Largest Digit(s)











up vote
23
down vote

favorite
4












Challenge:



Given a list of integer, sort descending by their single largest digit(s). The order for numbers with the same largest digit are then sorted by second largest digit, etc.

We ignore duplicated digits in numbers. And if all digits in a number are the same, the order of those numbers in the list can be in any way you'd like.



Example:



Input:            [123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373]
Possible outputs: [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0]
[8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0]


Why? Here are the relevant digits the numbers were sorted on:



Output:
[8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0 ]

Relevant digits they were sorted on:
[[9,8], [9,4], [8,7,6], [8,7,4], [8,7,3], [8,6], [7,3], [7,3], [3,2,1,0], [3,2,1], [0]]


Challenge rules:




  • We ignore duplicated digits, so 478 and -7738 will be ordered as 478, -7738, because the largest digits are [8,7,4] and [8,7,3], and not [8,7,4] and [8,7,7,3].

  • If multiple numbers have the same digits, the order of those can be either way. So 373 and -73 can be sorted as both 373, -73 or -73, 373 (digits are [7,3] for both of these numbers).

  • If a number contains no more digits to check, it will be placed at the back of the relevant numbers. So 123 and 3120 will be sorted as 3120, 123, because the largest digits [3,2,1] are the same, but 0 comes before none.

  • You can assume all numbers in the input are in the range [-999999,999999].

  • Just one of the possible outputs is enough as result, but you are allowed to output all possible outputs where sublists can be in any permutation if you want (although I doubt it would save bytes in any language).


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.


Test cases:



Input:            [123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373]
Possible outputs: [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0]
[8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0]

Input: [11, -312, 902, 23, 321, 2132, 34202, -34, -382]
Possible outputs: [902, -382, 34202, -34, -312, 321, 2132, 23, 11]
[902, -382, 34202, -34, 2132, -312, 321, 23, 11]
etc. The sublist [-312, 321, 2132] can be in any permutation

Input: [9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0]
Possible outputs: [29384, 192, 9, 6, 6, 4, 44, 2212, 21, 2, 1, 0]
[29384, 192, 9, 6, 6, 44, 4, 2212, 21, 2, 1, 0]
etc. The sublists [4, 44] and [2212, 21] can be in any permutation

Input: [44, -88, 9, 233, -3, 14, 101, 77, 555, 67]
Output: [9, -88, 67, 77, 555, 14, 44, 233, -3, 101]









share|improve this question


























    up vote
    23
    down vote

    favorite
    4












    Challenge:



    Given a list of integer, sort descending by their single largest digit(s). The order for numbers with the same largest digit are then sorted by second largest digit, etc.

    We ignore duplicated digits in numbers. And if all digits in a number are the same, the order of those numbers in the list can be in any way you'd like.



    Example:



    Input:            [123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373]
    Possible outputs: [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0]
    [8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0]


    Why? Here are the relevant digits the numbers were sorted on:



    Output:
    [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0 ]

    Relevant digits they were sorted on:
    [[9,8], [9,4], [8,7,6], [8,7,4], [8,7,3], [8,6], [7,3], [7,3], [3,2,1,0], [3,2,1], [0]]


    Challenge rules:




    • We ignore duplicated digits, so 478 and -7738 will be ordered as 478, -7738, because the largest digits are [8,7,4] and [8,7,3], and not [8,7,4] and [8,7,7,3].

    • If multiple numbers have the same digits, the order of those can be either way. So 373 and -73 can be sorted as both 373, -73 or -73, 373 (digits are [7,3] for both of these numbers).

    • If a number contains no more digits to check, it will be placed at the back of the relevant numbers. So 123 and 3120 will be sorted as 3120, 123, because the largest digits [3,2,1] are the same, but 0 comes before none.

    • You can assume all numbers in the input are in the range [-999999,999999].

    • Just one of the possible outputs is enough as result, but you are allowed to output all possible outputs where sublists can be in any permutation if you want (although I doubt it would save bytes in any language).


    General rules:




    • This is code-golf, so shortest answer in bytes wins.

      Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


    • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


    • Default Loopholes are forbidden.

    • If possible, please add a link with a test for your code (i.e. TIO).

    • Also, adding an explanation for your answer is highly recommended.


    Test cases:



    Input:            [123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373]
    Possible outputs: [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0]
    [8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0]

    Input: [11, -312, 902, 23, 321, 2132, 34202, -34, -382]
    Possible outputs: [902, -382, 34202, -34, -312, 321, 2132, 23, 11]
    [902, -382, 34202, -34, 2132, -312, 321, 23, 11]
    etc. The sublist [-312, 321, 2132] can be in any permutation

    Input: [9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0]
    Possible outputs: [29384, 192, 9, 6, 6, 4, 44, 2212, 21, 2, 1, 0]
    [29384, 192, 9, 6, 6, 44, 4, 2212, 21, 2, 1, 0]
    etc. The sublists [4, 44] and [2212, 21] can be in any permutation

    Input: [44, -88, 9, 233, -3, 14, 101, 77, 555, 67]
    Output: [9, -88, 67, 77, 555, 14, 44, 233, -3, 101]









    share|improve this question
























      up vote
      23
      down vote

      favorite
      4









      up vote
      23
      down vote

      favorite
      4






      4





      Challenge:



      Given a list of integer, sort descending by their single largest digit(s). The order for numbers with the same largest digit are then sorted by second largest digit, etc.

      We ignore duplicated digits in numbers. And if all digits in a number are the same, the order of those numbers in the list can be in any way you'd like.



      Example:



      Input:            [123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373]
      Possible outputs: [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0]
      [8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0]


      Why? Here are the relevant digits the numbers were sorted on:



      Output:
      [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0 ]

      Relevant digits they were sorted on:
      [[9,8], [9,4], [8,7,6], [8,7,4], [8,7,3], [8,6], [7,3], [7,3], [3,2,1,0], [3,2,1], [0]]


      Challenge rules:




      • We ignore duplicated digits, so 478 and -7738 will be ordered as 478, -7738, because the largest digits are [8,7,4] and [8,7,3], and not [8,7,4] and [8,7,7,3].

      • If multiple numbers have the same digits, the order of those can be either way. So 373 and -73 can be sorted as both 373, -73 or -73, 373 (digits are [7,3] for both of these numbers).

      • If a number contains no more digits to check, it will be placed at the back of the relevant numbers. So 123 and 3120 will be sorted as 3120, 123, because the largest digits [3,2,1] are the same, but 0 comes before none.

      • You can assume all numbers in the input are in the range [-999999,999999].

      • Just one of the possible outputs is enough as result, but you are allowed to output all possible outputs where sublists can be in any permutation if you want (although I doubt it would save bytes in any language).


      General rules:




      • This is code-golf, so shortest answer in bytes wins.

        Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


      • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


      • Default Loopholes are forbidden.

      • If possible, please add a link with a test for your code (i.e. TIO).

      • Also, adding an explanation for your answer is highly recommended.


      Test cases:



      Input:            [123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373]
      Possible outputs: [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0]
      [8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0]

      Input: [11, -312, 902, 23, 321, 2132, 34202, -34, -382]
      Possible outputs: [902, -382, 34202, -34, -312, 321, 2132, 23, 11]
      [902, -382, 34202, -34, 2132, -312, 321, 23, 11]
      etc. The sublist [-312, 321, 2132] can be in any permutation

      Input: [9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0]
      Possible outputs: [29384, 192, 9, 6, 6, 4, 44, 2212, 21, 2, 1, 0]
      [29384, 192, 9, 6, 6, 44, 4, 2212, 21, 2, 1, 0]
      etc. The sublists [4, 44] and [2212, 21] can be in any permutation

      Input: [44, -88, 9, 233, -3, 14, 101, 77, 555, 67]
      Output: [9, -88, 67, 77, 555, 14, 44, 233, -3, 101]









      share|improve this question













      Challenge:



      Given a list of integer, sort descending by their single largest digit(s). The order for numbers with the same largest digit are then sorted by second largest digit, etc.

      We ignore duplicated digits in numbers. And if all digits in a number are the same, the order of those numbers in the list can be in any way you'd like.



      Example:



      Input:            [123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373]
      Possible outputs: [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0]
      [8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0]


      Why? Here are the relevant digits the numbers were sorted on:



      Output:
      [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0 ]

      Relevant digits they were sorted on:
      [[9,8], [9,4], [8,7,6], [8,7,4], [8,7,3], [8,6], [7,3], [7,3], [3,2,1,0], [3,2,1], [0]]


      Challenge rules:




      • We ignore duplicated digits, so 478 and -7738 will be ordered as 478, -7738, because the largest digits are [8,7,4] and [8,7,3], and not [8,7,4] and [8,7,7,3].

      • If multiple numbers have the same digits, the order of those can be either way. So 373 and -73 can be sorted as both 373, -73 or -73, 373 (digits are [7,3] for both of these numbers).

      • If a number contains no more digits to check, it will be placed at the back of the relevant numbers. So 123 and 3120 will be sorted as 3120, 123, because the largest digits [3,2,1] are the same, but 0 comes before none.

      • You can assume all numbers in the input are in the range [-999999,999999].

      • Just one of the possible outputs is enough as result, but you are allowed to output all possible outputs where sublists can be in any permutation if you want (although I doubt it would save bytes in any language).


      General rules:




      • This is code-golf, so shortest answer in bytes wins.

        Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


      • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


      • Default Loopholes are forbidden.

      • If possible, please add a link with a test for your code (i.e. TIO).

      • Also, adding an explanation for your answer is highly recommended.


      Test cases:



      Input:            [123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373]
      Possible outputs: [8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0]
      [8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0]

      Input: [11, -312, 902, 23, 321, 2132, 34202, -34, -382]
      Possible outputs: [902, -382, 34202, -34, -312, 321, 2132, 23, 11]
      [902, -382, 34202, -34, 2132, -312, 321, 23, 11]
      etc. The sublist [-312, 321, 2132] can be in any permutation

      Input: [9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0]
      Possible outputs: [29384, 192, 9, 6, 6, 4, 44, 2212, 21, 2, 1, 0]
      [29384, 192, 9, 6, 6, 44, 4, 2212, 21, 2, 1, 0]
      etc. The sublists [4, 44] and [2212, 21] can be in any permutation

      Input: [44, -88, 9, 233, -3, 14, 101, 77, 555, 67]
      Output: [9, -88, 67, 77, 555, 14, 44, 233, -3, 101]






      code-golf number integer sorting






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 at 9:41









      Kevin Cruijssen

      35.2k554186




      35.2k554186






















          25 Answers
          25






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted











          05AB1E, 5 bytes



          ΣêR}R


          Try it online!
          or as a Test suite



          Explanation



          Σ  }    # sort input by
          ê # its sorted unique characters
          R # reversed (to sort descending)
          R # reverse the result (to sort descending)





          share|improve this answer






























            up vote
            7
            down vote














            R, 97 95 bytes





            function(x)x[rev(order(sapply(Map(sort,Map(unique,strsplit(paste(x),"")),T),Reduce,f=paste0)))]


            Try it online!



            This challenge seems to have been pessimized for R. Explanation of the original version (start at 1. and work up):



            f <- function(x) {
            x[ # 8. Input vector in
            rev( # 7. Reversed
            order( # 6. Lexicographical order
            sapply( # 5. Paste....
            Map(sort, # 4. Sort each using...
            Map(unique, # 3. Deduplicate each
            strsplit( # 2. Split each string into characters
            paste(x), # 1. Coerce each number to string
            "")),
            T), # 4. ...descending sort.
            paste,collapse="") # 5. ...back into strings
            )
            )
            ]
            }





            share|improve this answer






























              up vote
              6
              down vote














              Perl 6, 36 34 33 31 bytes



              -1 byte thanks to Jo King
              -2 bytes thanks to Phil H





              *.sort:{sort 1,|set -<<m:g/d/}


              Try it online!



              Explanation



                     {                      }  # Map each number, e.g. -373
              m:g/d/ # Extract digits: (3, 7, 3)
              -<< # Negate each digit: (-3, -7, -3)
              set # Convert to set to remove duplicates
              | # Pass as list of pairs: (-3 => True, -7 => True)
              1, # Prepend 1 for "none": (1, -3 => True, -7 => True)
              sort # Sort (compares 1 and pair by string value): (-7 => True, -3 => True, 1)
              *.sort: # Sort lexicographically





              share|improve this answer



















              • 1




                Nice! -2 bytes for swapping m:g/d./ for .abs.comb: tio.run/…
                – Phil H
                Nov 16 at 14:43


















              up vote
              6
              down vote














              Python 2, 60 55 54 bytes



              -1 byte thanks to Jonas Ausevicius.





              def f(l):l.sort(cmp,lambda n:sorted(set(`n`))[::-1],1)


              Try it online!





              Ungolfed





              def f(l):
              l.sort( # Sort the list in place
              cmp = cmp, # ... compare with the builtin function cmp
              key = k, # ... on the function k
              reverse = 1 # ... in reverse
              ) # As the arguments are used in the right order, no names are necessary.

              k = lambda n:sorted( # sort
              set(`n`) # ... the set of digits
              )[::-1] # reverse the result
              # As '-' is smaller than the digits,
              # it will be sorted to the back and ignored for sorting


              Try it online!






              share|improve this answer



















              • 5




                None can be replaced with cmp in sort function
                – Jonas Ausevicius
                Nov 15 at 10:14










              • The [::-1] can be exchanged for a double negation, I think.
                – DonQuiKong
                Nov 16 at 9:30










              • @DonQuiKong that would be quite a bit longer though, as the digits are all strings, and would need to be converted to ints for this.
                – ovs
                Nov 17 at 14:05










              • @JonasAusevicius Thanks a lot.
                – ovs
                Nov 17 at 14:12


















              up vote
              5
              down vote














              Python 2, 58 60 bytes



              lambda a:sorted(a,key=lambda x:sorted(set(`x`))[::-1])[::-1]



              Try it online!






              share|improve this answer




























                up vote
                5
                down vote














                Brachylog, 9 bytes



                {ȧdṫo₁}ᵒ¹


                Note: due to how ordering works in brachylog, it does not work on number correctly. This is fixed by casting the number to a string () at the cost of 1 byte.



                Try it online!






                share|improve this answer



















                • 2




                  What do you mean by "Due to how ordering works in brachylog, it does not work as intended."? I've tried all four test cases, and its giving the correct results (unless I accidentally looked past something).
                  – Kevin Cruijssen
                  Nov 15 at 10:12










                • @KevinCruijssen The (to string) fixes the issue. Ordering digits in a number descending works as follows. Order from smallest to largest then reverse. The problem is that the number 3120 ordered from smallest to largest is 0123 which is equal to 123which reversed is 321and not 3210
                  – Kroppeb
                  Nov 15 at 11:00






                • 2




                  Ah ok, so your current code is working due to the added toString (). As mentioned by @Arnauld, I thought your comment meant your current code doesn't work. It might be better to mention it like: "This could have been 8 bytes by removing the (toString), but unfortunately it does not work as intended due to how ordering works in Brachylog."
                  – Kevin Cruijssen
                  Nov 15 at 11:12










                • Looking at what I wrote it seems that my brain got distracted midsentence. Fixed it.
                  – Kroppeb
                  Nov 15 at 11:31


















                up vote
                5
                down vote













                Pyth, 7 6 bytes



                -1 byte by @Sok



                _o_{S`


                Pyth, which uses only printable ASCII, is at a bit of a disadvantage here. Optimally encoded this would be 6*log(95)/log(256) = 4.927 bytes, beating 05AB1E.



                Explained:



                 o              Sort the implicit input by lambda N:
                _ reversed
                { uniquified
                S sorted
                ' string representation [of N]
                _ then reverse the result.


                Try it here.






                share|improve this answer



















                • 2




                  The trailing N can be left out to save 1 byte - all lambda-type functions infer the presence of the principle lambda variable if any arguments are missing from the end. Examples include m inferring d, f inferring T, u inferring G...
                  – Sok
                  Nov 15 at 12:08




















                up vote
                4
                down vote














                Jelly, 8 bytes



                ADṢUQµÞU


                Try it online!



                How it works



                ADṢUQµÞU  Main link (monad). Input: integer list
                µÞU Sort by (reversed):
                AD Absolute value converted to decimal digits
                ṢUQ Sort, reverse, take unique values





                share|improve this answer

















                • 2




                  I just implemented this then found your post. I went with normal reverses, , rather than the upends, U. Note, however, that you do not need the D since sort, , is implemented with an iterable(z, make_digits=True) call inside. So that was AṢQṚµÞṚ for 7.
                  – Jonathan Allan
                  Nov 15 at 18:16


















                up vote
                3
                down vote














                MathGolf, 7 6 bytes



                áÉ░▀zx


                Try it online! or as a test suite.



                Explanation



                After looking at Emigna's 05AB1E solution, I found that I didn't need the absolute operator (and my previous answer was actually incorrect because of that operator). Now the main difference is that I convert to string and get unique characters instead of using the 1-byte operator in 05AB1E.



                áÉ      Sort by the value generated from mapping each element using the next 3 instructions
                ░ Convert to string
                ▀ Get unique characters
                z Sort reversed (last instruction of block)
                x Reverse list (needed because I don't have a sort-reversed by mapping)





                share|improve this answer






























                  up vote
                  3
                  down vote














                  Japt, 12 bytes



                  ñ_a ì â ñnÃw


                  All test cases



                  Explanation:



                  ñ_        Ãw    :Sort Descending by:
                  a : Get the absolute value
                  ì : Get the digits
                  â : Remove duplicates
                  ñn : Sort the digits in descending order





                  share|improve this answer






























                    up vote
                    3
                    down vote














                    Haskell, 54 52 bytes





                    import Data.List
                    f=r.sortOn(r.sort.nub.show);r=reverse


                    Try it online!






                    share|improve this answer























                    • Defining r=reverse saves two bytes. We also allow anonymous functions, so the f= does not need to ve counted.
                      – Laikoni
                      Nov 15 at 23:33










                    • I moved the import and f= to the TIO header. Is that OK?
                      – Martin Lütke
                      Nov 15 at 23:34










                    • Same byte count, but maybe of some interest: f=r$r id.nub.show;r=(reverse.).sortOn.
                      – Laikoni
                      Nov 15 at 23:43






                    • 1




                      The import actually needs to be counted.
                      – Laikoni
                      Nov 15 at 23:45






                    • 2




                      You may want to have a look at our Guide to golfing rules in Haskell.
                      – Laikoni
                      Nov 15 at 23:52


















                    up vote
                    3
                    down vote














                    Stax, 6 7 bytes



                    èó≥ü≤♥¥


                    Run and debug it






                    share|improve this answer























                    • This seems to give incorrect results. For example, in the test case of your TIO it outputs -904 8491 478 62778 6458 -7738 -73 373 123 3120 0 instead of the intended 8491 -904 62778 478 -7738 6458 373 -73 3120 123 0 or 8491 -904 62778 478 -7738 6458 -73 373 3120 123 0. This test case is also used in the example, and to explain the rules, so I would take a look at that to understand it better. It seems you are only sorting by the single largest digit once, without any of the other rules?
                      – Kevin Cruijssen
                      Nov 16 at 7:37












                    • @KevinCruijssen: Yes, my apologies. I mis-read the problem statement. I've adjusted the program to handle the stated requirements. This program is accepting the input integers as quoted strings. That's usually acceptable, but if not I might need to add another byte.
                      – recursive
                      Nov 16 at 17:23










                    • Looks good now, +1 from me. And yes, inputting as strings is completely fine.
                      – Kevin Cruijssen
                      Nov 16 at 17:54


















                    up vote
                    3
                    down vote














                    APL (Dyalog Extended), 19 bytes





                    {⍵[⍒∪¨(∨'¯'~⍨⍕)¨⍵]}


                    Try it online!



                    Fixed at a cost of +2 bytes thanks to OP.






                    share|improve this answer























                    • I think you are missing an 'uniquify' somewhere? If I try the example test case in your TIO for example, ¯7738 is placed before 478, but it should be after it: digits [8,7,4] come before digits [8,7,3].
                      – Kevin Cruijssen
                      Nov 16 at 17:52










                    • Thanks, @KevinCruijssen
                      – Zacharý
                      Nov 16 at 21:06


















                    up vote
                    3
                    down vote














                    C (gcc), 114 111 109 bytes





                    a;v(n){n=n<0?-n:n;for(a=0;n;n/=10)a|=1<<n%10;n=a;}c(int*a,int*b){a=v(*a)<v(*b);}f(a,n)int*a;{qsort(a,n,4,c);}


                    Try it online!



                    Explanation:



                    f() uses qsort() to sort provided array in place. Using comparison function c() to compare numbers which evaluates numbers using v().
                    v() calculates a higher number if bigger digits are present in parameter.



                    [Edit 1]
                    Improved by 3 bytes. 2 byte credits to Kevin. Thanks



                    [Edit 2] 2 more bytes improved. Credits to gastropner. Thanks






                    share|improve this answer



















                    • 1




                      You can golf n>0 to n I think in your loop of your method v.
                      – Kevin Cruijssen
                      Nov 15 at 11:55










                    • f()'s argument list int*a,n can be shortened to int*a.
                      – gastropner
                      Nov 19 at 6:58






                    • 1




                      Suggest for(a=0;n=abs(n); instead of n=n<0?-n:n;for(a=0;n;
                      – ceilingcat
                      Nov 20 at 8:31


















                    up vote
                    2
                    down vote














                    J, 17 bytes



                    {~[::~.@:~@":@|


                    Try it online!



                    Explanation:



                                    @|    - find the absolute value and
                    @": - convert to string and
                    @:~ - sort down and
                    ~. - keep only the unique symbols
                    : - grade down the entire list of strings
                    [: - function composition
                    {~ - use the graded-down list to index into the input





                    share|improve this answer






























                      up vote
                      2
                      down vote














                      JavaScript (SpiderMonkey), 68 bytes



                      Thanks for @Arnauld for reminding me again that SpiderMonkey uses stable sort, so -4 bytes for removing ||-1.





                      A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y))


                      Try it online!




                      JavaScript (Node.js), 72 bytes





                      A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y)||-1)


                      Try it online!






                      share|improve this answer























                      • Or 68 bytes with SpiderMonkey.
                        – Arnauld
                        Nov 15 at 11:04






                      • 1




                        @Arnauld oh stable sort again ;P
                        – Shieru Asakoto
                        Nov 15 at 12:17










                      • Actually, I think V8 is using at least 2 different sort algorithms. It seems like it's stable if the size of the array is less than or equal to $10$.
                        – Arnauld
                        Nov 15 at 12:37






                      • 1




                        @Arnauld V8 use quick sort before Chrome 70. The quick sort algorithm perform an insertion sort when array size is small enough. And latest Chrome had changed to stable sort for matching other browsers' (IE/Firefox/Safari) behavior.
                        – tsh
                        Nov 16 at 8:42


















                      up vote
                      2
                      down vote














                      Java (JDK), 98 bytes





                      l->l.sort((a,b)->{int r=0,i=58;for(;r==0&i-->48;)r=(b.indexOf(i)>>9)-(a.indexOf(i)>>9);return r;})


                      Try it online!



                      Explanation



                      l->                           // Consumer<List<String>>
                      l.sort( // Use the incorporated sort method which uses a...
                      (a,b)->{ // Comparator of Strings
                      int r=0, // define r as the result, initiated to 0
                      i=58; // i as the codepoint to test for.
                      for(;r==0&i-->48;) // for each digit codepoint from '9' to '0',
                      // and while no difference was found.
                      r= // set r as the difference between
                      (b.indexOf(i)>>9)- // was the digit found in b? then 0 else -1 using the bit-shift operator
                      (a.indexOf(i)>>9); // and was the digit found in a? then 0 else -1.
                      return r; // return the comparison result.
                      }
                      )


                      Note:



                      I needed a way to map numbers to either 0/1 or 0/-1.



                      indexOf has the nice property that it's consistently returning -1 for characters not found. -1 right-shifted by any number is always -1. Any positive number right-shifted by a big enough number will always produce 0.



                      So here we are:



                      input        input.indexOf('9')      input.indexOf('9')>>9
                      "999" 0 0
                      "111119" 5 0
                      "123456" -1 -1





                      share|improve this answer



















                      • 1




                        Ah, yeah, that's what I mean. ;p Nice golf of using >>9 instead of >>32 due to the limited range of the numbers.
                        – Kevin Cruijssen
                        Nov 15 at 12:53


















                      up vote
                      1
                      down vote














                      Ruby, 55 bytes





                      ->a{a.sort_by{|x|x.abs.digits.sort.reverse|}.reverse}


                      Try it online!






                      share|improve this answer




























                        up vote
                        1
                        down vote














                        Perl 5 -nl, 68 bytes





                        $a{eval"9876543210=~y/$_//dcr"}=$_}{say$a{$_}for reverse sort keys%a


                        Try it online!






                        share|improve this answer




























                          up vote
                          1
                          down vote














                          Julia 1.0, 50 bytes





                          x->sort(x,by=y->sort(unique([digits(-abs(y));1])))


                          Try it online!






                          share|improve this answer




























                            up vote
                            1
                            down vote













                            APL(NARS), 366 chars, 732 bytes



                            _gb←⍬

                            ∇a _s w;t
                            t←_gb[a]⋄_gb[a]←_gb[w]⋄_gb[w]←t


                            ∇(_f _q)w;l;r;ls;i
                            (l r)←w⋄→0×⍳l≥r⋄l _s⌊2÷⍨l+r⋄ls←i←l⋄→3
                            →3×⍳∼0<_gb[i]_f _gb[l]⋄ls+←1⋄ls _s i
                            →2×⍳r≥i+←1
                            l _s ls⋄_f _q l(ls-1)⋄_f _q(ls+1)r


                            ∇r←(a qsort)w
                            r←¯1⋄→0×⍳1≠⍴⍴w⋄_gb←w⋄a _q 1(↑⍴w)⋄r←_gb


                            f←{∪t[⍒t←⍎¨⍕∣⍵]}

                            ∇r←a c b;x;y;i;m
                            x←f a⋄y←f b⋄r←i←0⋄m←(↑⍴x)⌊(↑⍴y)⋄→3
                            →0×⍳x[i]<y[i]⋄→3×⍳∼x[i]>y[i]⋄r←1⋄→0
                            →2×⍳m≥i+←1⋄r←(↑⍴x)>(↑⍴y)



                            For the qsort operator, it is one traslation in APL of algo page 139 K&R Linguaggio C.
                            I think in it there is using data as C with pointers...
                            Test



                             c qsort 123, 478, ¯904, 62778, 0, ¯73, 8491, 3120, 6458, ¯7738, 373 
                            8491 ¯904 62778 478 ¯7738 6458 ¯73 373 3120 123 0
                            c qsort 11, ¯312, 902, 23, 321, 2132, 34202, ¯34, ¯382
                            902 ¯382 34202 ¯34 321 ¯312 2132 23 11
                            c qsort 9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0
                            29384 192 9 6 6 4 44 2212 21 2 1 0
                            c qsort 44, ¯88, 9, 233, ¯3, 14, 101, 77, 555, 67
                            9 ¯88 67 77 555 14 44 233 ¯3 101





                            share|improve this answer




























                              up vote
                              1
                              down vote













                              Powershell, 44 bytes





                              $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d


                              Test script:



                              $f = {

                              $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d

                              }

                              @(
                              ,( (123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373),
                              (8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0),
                              (8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0) )

                              ,( (11, -312, 902, 23, 321, 2132, 34202, -34, -382),
                              (902, -382, 34202, -34, -312, 321, 2132, 23, 11),
                              (902, -382, 34202, -34, 2132, -312, 321, 23, 11) )

                              ,( (9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0),
                              (29384, 192, 9, 6, 6, 4, 44, 2212, 21, 2, 1, 0),
                              (29384, 192, 9, 6, 6, 44, 4, 2212, 21, 2, 1, 0),
                              (29384, 192, 9, 6, 6, 44, 4, 21, 2212, 2, 1, 0) )

                              ,( (44, -88, 9, 233, -3, 14, 101, 77, 555, 67),
                              ,(9, -88, 67, 77, 555, 14, 44, 233, -3, 101) )
                              ) | % {
                              $a, $expected = $_
                              $result = &$f @a
                              $true-in($expected|%{"$result"-eq"$_"})
                              "$result"
                              }


                              Output:



                              True
                              8491 -904 62778 478 -7738 6458 -73 373 3120 123 0
                              True
                              902 -382 34202 -34 2132 -312 321 23 11
                              True
                              29384 192 9 6 6 44 4 21 2212 2 1 0
                              True
                              9 -88 67 77 555 14 44 233 -3 101





                              share|improve this answer




























                                up vote
                                1
                                down vote













                                PHP, 87 86 84 bytes





                                while(--$argc)$a[_.strrev(count_chars($n=$argv[++$i],3))]=$n;krsort($a);print_r($a);


                                Run with -nr or try it online.



                                Replace ++$i with $argc (+1 byte) to suppress the Notice (and render -n obosolete).



                                breakdown



                                while(--$argc)  # loop through command line arguments
                                $a[ # key=
                                _. # 3. prepend non-numeric char for non-numeric sort
                                strrev( # 2. reverse =^= sort descending
                                count_chars($n=$argv[++$i],3) # 1. get characters used in argument
                                )
                                ]=$n; # value=argument
                                krsort($a); # sort by key descending
                                print_r($a); # print


                                - is "smaller" than the digits, so it has no affect on the sorting.






                                share|improve this answer






























                                  up vote
                                  1
                                  down vote













                                  Common Lisp, 88 bytes





                                  (sort(read)'string> :key(lambda(x)(sort(remove-duplicates(format()"~d"(abs x)))'char>)))


                                  Try it online!



                                  Good old verbose Common Lisp!



                                  Explanation:



                                  (sort                   ; sort
                                  (read) ; what to sort: a list of numbers, read on input stream
                                  'string> ; comparison predicate (remember: this is a typed language!)
                                  :key (lambda (x) ; how to get an element to sort; get a number
                                  (sort (remove-duplicates ; then sort the unique digits (characters)
                                  (format() "~d" (abs x))) ; from its string representation
                                  'char>))) ; with the appropriate comparison operator for characters





                                  share|improve this answer






























                                    up vote
                                    1
                                    down vote














                                    C# (Visual C# Interactive Compiler), 75 74 bytes



                                    -1 thanks @ASCII-only





                                    x=>x.OrderByDescending(y=>String.Concat((y+"").Distinct().OrderBy(z=>-z)))


                                    Try it online!



                                    In C#, strings are considered "enumerables" of characters. I use this to my advantage by first converting each number to a string. LINQ is then leveraged to get the unique characters (digits) sorted in reverse order. I convert each sorted character array back into a string and use that as the sort key to order the whole list.






                                    share|improve this answer























                                    • Looks like you'll be able to get away with not adding -, looks like order of those doesn't really matter?
                                      – ASCII-only
                                      Nov 18 at 9:47












                                    • Without the -, test case #2 returns ... 321 2132 ... which seems incorrect?
                                      – dana
                                      Nov 18 at 16:11










                                    • nah, read the example more carefully
                                      – ASCII-only
                                      Nov 18 at 21:52










                                    • OK - I think your right. Thanks for the tip!
                                      – dana
                                      Nov 18 at 22:24











                                    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: 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%2f175978%2fsort-by-largest-digits%23new-answer', 'question_page');
                                    }
                                    );

                                    Post as a guest















                                    Required, but never shown

























                                    25 Answers
                                    25






                                    active

                                    oldest

                                    votes








                                    25 Answers
                                    25






                                    active

                                    oldest

                                    votes









                                    active

                                    oldest

                                    votes






                                    active

                                    oldest

                                    votes








                                    up vote
                                    6
                                    down vote



                                    accepted











                                    05AB1E, 5 bytes



                                    ΣêR}R


                                    Try it online!
                                    or as a Test suite



                                    Explanation



                                    Σ  }    # sort input by
                                    ê # its sorted unique characters
                                    R # reversed (to sort descending)
                                    R # reverse the result (to sort descending)





                                    share|improve this answer



























                                      up vote
                                      6
                                      down vote



                                      accepted











                                      05AB1E, 5 bytes



                                      ΣêR}R


                                      Try it online!
                                      or as a Test suite



                                      Explanation



                                      Σ  }    # sort input by
                                      ê # its sorted unique characters
                                      R # reversed (to sort descending)
                                      R # reverse the result (to sort descending)





                                      share|improve this answer

























                                        up vote
                                        6
                                        down vote



                                        accepted







                                        up vote
                                        6
                                        down vote



                                        accepted







                                        05AB1E, 5 bytes



                                        ΣêR}R


                                        Try it online!
                                        or as a Test suite



                                        Explanation



                                        Σ  }    # sort input by
                                        ê # its sorted unique characters
                                        R # reversed (to sort descending)
                                        R # reverse the result (to sort descending)





                                        share|improve this answer















                                        05AB1E, 5 bytes



                                        ΣêR}R


                                        Try it online!
                                        or as a Test suite



                                        Explanation



                                        Σ  }    # sort input by
                                        ê # its sorted unique characters
                                        R # reversed (to sort descending)
                                        R # reverse the result (to sort descending)






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Nov 15 at 10:04

























                                        answered Nov 15 at 9:47









                                        Emigna

                                        45.1k432138




                                        45.1k432138






















                                            up vote
                                            7
                                            down vote














                                            R, 97 95 bytes





                                            function(x)x[rev(order(sapply(Map(sort,Map(unique,strsplit(paste(x),"")),T),Reduce,f=paste0)))]


                                            Try it online!



                                            This challenge seems to have been pessimized for R. Explanation of the original version (start at 1. and work up):



                                            f <- function(x) {
                                            x[ # 8. Input vector in
                                            rev( # 7. Reversed
                                            order( # 6. Lexicographical order
                                            sapply( # 5. Paste....
                                            Map(sort, # 4. Sort each using...
                                            Map(unique, # 3. Deduplicate each
                                            strsplit( # 2. Split each string into characters
                                            paste(x), # 1. Coerce each number to string
                                            "")),
                                            T), # 4. ...descending sort.
                                            paste,collapse="") # 5. ...back into strings
                                            )
                                            )
                                            ]
                                            }





                                            share|improve this answer



























                                              up vote
                                              7
                                              down vote














                                              R, 97 95 bytes





                                              function(x)x[rev(order(sapply(Map(sort,Map(unique,strsplit(paste(x),"")),T),Reduce,f=paste0)))]


                                              Try it online!



                                              This challenge seems to have been pessimized for R. Explanation of the original version (start at 1. and work up):



                                              f <- function(x) {
                                              x[ # 8. Input vector in
                                              rev( # 7. Reversed
                                              order( # 6. Lexicographical order
                                              sapply( # 5. Paste....
                                              Map(sort, # 4. Sort each using...
                                              Map(unique, # 3. Deduplicate each
                                              strsplit( # 2. Split each string into characters
                                              paste(x), # 1. Coerce each number to string
                                              "")),
                                              T), # 4. ...descending sort.
                                              paste,collapse="") # 5. ...back into strings
                                              )
                                              )
                                              ]
                                              }





                                              share|improve this answer

























                                                up vote
                                                7
                                                down vote










                                                up vote
                                                7
                                                down vote










                                                R, 97 95 bytes





                                                function(x)x[rev(order(sapply(Map(sort,Map(unique,strsplit(paste(x),"")),T),Reduce,f=paste0)))]


                                                Try it online!



                                                This challenge seems to have been pessimized for R. Explanation of the original version (start at 1. and work up):



                                                f <- function(x) {
                                                x[ # 8. Input vector in
                                                rev( # 7. Reversed
                                                order( # 6. Lexicographical order
                                                sapply( # 5. Paste....
                                                Map(sort, # 4. Sort each using...
                                                Map(unique, # 3. Deduplicate each
                                                strsplit( # 2. Split each string into characters
                                                paste(x), # 1. Coerce each number to string
                                                "")),
                                                T), # 4. ...descending sort.
                                                paste,collapse="") # 5. ...back into strings
                                                )
                                                )
                                                ]
                                                }





                                                share|improve this answer















                                                R, 97 95 bytes





                                                function(x)x[rev(order(sapply(Map(sort,Map(unique,strsplit(paste(x),"")),T),Reduce,f=paste0)))]


                                                Try it online!



                                                This challenge seems to have been pessimized for R. Explanation of the original version (start at 1. and work up):



                                                f <- function(x) {
                                                x[ # 8. Input vector in
                                                rev( # 7. Reversed
                                                order( # 6. Lexicographical order
                                                sapply( # 5. Paste....
                                                Map(sort, # 4. Sort each using...
                                                Map(unique, # 3. Deduplicate each
                                                strsplit( # 2. Split each string into characters
                                                paste(x), # 1. Coerce each number to string
                                                "")),
                                                T), # 4. ...descending sort.
                                                paste,collapse="") # 5. ...back into strings
                                                )
                                                )
                                                ]
                                                }






                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Nov 15 at 17:38

























                                                answered Nov 15 at 14:56









                                                ngm

                                                3,11923




                                                3,11923






















                                                    up vote
                                                    6
                                                    down vote














                                                    Perl 6, 36 34 33 31 bytes



                                                    -1 byte thanks to Jo King
                                                    -2 bytes thanks to Phil H





                                                    *.sort:{sort 1,|set -<<m:g/d/}


                                                    Try it online!



                                                    Explanation



                                                           {                      }  # Map each number, e.g. -373
                                                    m:g/d/ # Extract digits: (3, 7, 3)
                                                    -<< # Negate each digit: (-3, -7, -3)
                                                    set # Convert to set to remove duplicates
                                                    | # Pass as list of pairs: (-3 => True, -7 => True)
                                                    1, # Prepend 1 for "none": (1, -3 => True, -7 => True)
                                                    sort # Sort (compares 1 and pair by string value): (-7 => True, -3 => True, 1)
                                                    *.sort: # Sort lexicographically





                                                    share|improve this answer



















                                                    • 1




                                                      Nice! -2 bytes for swapping m:g/d./ for .abs.comb: tio.run/…
                                                      – Phil H
                                                      Nov 16 at 14:43















                                                    up vote
                                                    6
                                                    down vote














                                                    Perl 6, 36 34 33 31 bytes



                                                    -1 byte thanks to Jo King
                                                    -2 bytes thanks to Phil H





                                                    *.sort:{sort 1,|set -<<m:g/d/}


                                                    Try it online!



                                                    Explanation



                                                           {                      }  # Map each number, e.g. -373
                                                    m:g/d/ # Extract digits: (3, 7, 3)
                                                    -<< # Negate each digit: (-3, -7, -3)
                                                    set # Convert to set to remove duplicates
                                                    | # Pass as list of pairs: (-3 => True, -7 => True)
                                                    1, # Prepend 1 for "none": (1, -3 => True, -7 => True)
                                                    sort # Sort (compares 1 and pair by string value): (-7 => True, -3 => True, 1)
                                                    *.sort: # Sort lexicographically





                                                    share|improve this answer



















                                                    • 1




                                                      Nice! -2 bytes for swapping m:g/d./ for .abs.comb: tio.run/…
                                                      – Phil H
                                                      Nov 16 at 14:43













                                                    up vote
                                                    6
                                                    down vote










                                                    up vote
                                                    6
                                                    down vote










                                                    Perl 6, 36 34 33 31 bytes



                                                    -1 byte thanks to Jo King
                                                    -2 bytes thanks to Phil H





                                                    *.sort:{sort 1,|set -<<m:g/d/}


                                                    Try it online!



                                                    Explanation



                                                           {                      }  # Map each number, e.g. -373
                                                    m:g/d/ # Extract digits: (3, 7, 3)
                                                    -<< # Negate each digit: (-3, -7, -3)
                                                    set # Convert to set to remove duplicates
                                                    | # Pass as list of pairs: (-3 => True, -7 => True)
                                                    1, # Prepend 1 for "none": (1, -3 => True, -7 => True)
                                                    sort # Sort (compares 1 and pair by string value): (-7 => True, -3 => True, 1)
                                                    *.sort: # Sort lexicographically





                                                    share|improve this answer















                                                    Perl 6, 36 34 33 31 bytes



                                                    -1 byte thanks to Jo King
                                                    -2 bytes thanks to Phil H





                                                    *.sort:{sort 1,|set -<<m:g/d/}


                                                    Try it online!



                                                    Explanation



                                                           {                      }  # Map each number, e.g. -373
                                                    m:g/d/ # Extract digits: (3, 7, 3)
                                                    -<< # Negate each digit: (-3, -7, -3)
                                                    set # Convert to set to remove duplicates
                                                    | # Pass as list of pairs: (-3 => True, -7 => True)
                                                    1, # Prepend 1 for "none": (1, -3 => True, -7 => True)
                                                    sort # Sort (compares 1 and pair by string value): (-7 => True, -3 => True, 1)
                                                    *.sort: # Sort lexicographically






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Nov 16 at 14:50

























                                                    answered Nov 15 at 10:52









                                                    nwellnhof

                                                    6,4331125




                                                    6,4331125








                                                    • 1




                                                      Nice! -2 bytes for swapping m:g/d./ for .abs.comb: tio.run/…
                                                      – Phil H
                                                      Nov 16 at 14:43














                                                    • 1




                                                      Nice! -2 bytes for swapping m:g/d./ for .abs.comb: tio.run/…
                                                      – Phil H
                                                      Nov 16 at 14:43








                                                    1




                                                    1




                                                    Nice! -2 bytes for swapping m:g/d./ for .abs.comb: tio.run/…
                                                    – Phil H
                                                    Nov 16 at 14:43




                                                    Nice! -2 bytes for swapping m:g/d./ for .abs.comb: tio.run/…
                                                    – Phil H
                                                    Nov 16 at 14:43










                                                    up vote
                                                    6
                                                    down vote














                                                    Python 2, 60 55 54 bytes



                                                    -1 byte thanks to Jonas Ausevicius.





                                                    def f(l):l.sort(cmp,lambda n:sorted(set(`n`))[::-1],1)


                                                    Try it online!





                                                    Ungolfed





                                                    def f(l):
                                                    l.sort( # Sort the list in place
                                                    cmp = cmp, # ... compare with the builtin function cmp
                                                    key = k, # ... on the function k
                                                    reverse = 1 # ... in reverse
                                                    ) # As the arguments are used in the right order, no names are necessary.

                                                    k = lambda n:sorted( # sort
                                                    set(`n`) # ... the set of digits
                                                    )[::-1] # reverse the result
                                                    # As '-' is smaller than the digits,
                                                    # it will be sorted to the back and ignored for sorting


                                                    Try it online!






                                                    share|improve this answer



















                                                    • 5




                                                      None can be replaced with cmp in sort function
                                                      – Jonas Ausevicius
                                                      Nov 15 at 10:14










                                                    • The [::-1] can be exchanged for a double negation, I think.
                                                      – DonQuiKong
                                                      Nov 16 at 9:30










                                                    • @DonQuiKong that would be quite a bit longer though, as the digits are all strings, and would need to be converted to ints for this.
                                                      – ovs
                                                      Nov 17 at 14:05










                                                    • @JonasAusevicius Thanks a lot.
                                                      – ovs
                                                      Nov 17 at 14:12















                                                    up vote
                                                    6
                                                    down vote














                                                    Python 2, 60 55 54 bytes



                                                    -1 byte thanks to Jonas Ausevicius.





                                                    def f(l):l.sort(cmp,lambda n:sorted(set(`n`))[::-1],1)


                                                    Try it online!





                                                    Ungolfed





                                                    def f(l):
                                                    l.sort( # Sort the list in place
                                                    cmp = cmp, # ... compare with the builtin function cmp
                                                    key = k, # ... on the function k
                                                    reverse = 1 # ... in reverse
                                                    ) # As the arguments are used in the right order, no names are necessary.

                                                    k = lambda n:sorted( # sort
                                                    set(`n`) # ... the set of digits
                                                    )[::-1] # reverse the result
                                                    # As '-' is smaller than the digits,
                                                    # it will be sorted to the back and ignored for sorting


                                                    Try it online!






                                                    share|improve this answer



















                                                    • 5




                                                      None can be replaced with cmp in sort function
                                                      – Jonas Ausevicius
                                                      Nov 15 at 10:14










                                                    • The [::-1] can be exchanged for a double negation, I think.
                                                      – DonQuiKong
                                                      Nov 16 at 9:30










                                                    • @DonQuiKong that would be quite a bit longer though, as the digits are all strings, and would need to be converted to ints for this.
                                                      – ovs
                                                      Nov 17 at 14:05










                                                    • @JonasAusevicius Thanks a lot.
                                                      – ovs
                                                      Nov 17 at 14:12













                                                    up vote
                                                    6
                                                    down vote










                                                    up vote
                                                    6
                                                    down vote










                                                    Python 2, 60 55 54 bytes



                                                    -1 byte thanks to Jonas Ausevicius.





                                                    def f(l):l.sort(cmp,lambda n:sorted(set(`n`))[::-1],1)


                                                    Try it online!





                                                    Ungolfed





                                                    def f(l):
                                                    l.sort( # Sort the list in place
                                                    cmp = cmp, # ... compare with the builtin function cmp
                                                    key = k, # ... on the function k
                                                    reverse = 1 # ... in reverse
                                                    ) # As the arguments are used in the right order, no names are necessary.

                                                    k = lambda n:sorted( # sort
                                                    set(`n`) # ... the set of digits
                                                    )[::-1] # reverse the result
                                                    # As '-' is smaller than the digits,
                                                    # it will be sorted to the back and ignored for sorting


                                                    Try it online!






                                                    share|improve this answer















                                                    Python 2, 60 55 54 bytes



                                                    -1 byte thanks to Jonas Ausevicius.





                                                    def f(l):l.sort(cmp,lambda n:sorted(set(`n`))[::-1],1)


                                                    Try it online!





                                                    Ungolfed





                                                    def f(l):
                                                    l.sort( # Sort the list in place
                                                    cmp = cmp, # ... compare with the builtin function cmp
                                                    key = k, # ... on the function k
                                                    reverse = 1 # ... in reverse
                                                    ) # As the arguments are used in the right order, no names are necessary.

                                                    k = lambda n:sorted( # sort
                                                    set(`n`) # ... the set of digits
                                                    )[::-1] # reverse the result
                                                    # As '-' is smaller than the digits,
                                                    # it will be sorted to the back and ignored for sorting


                                                    Try it online!







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Nov 17 at 14:12

























                                                    answered Nov 15 at 9:54









                                                    ovs

                                                    18.6k21059




                                                    18.6k21059








                                                    • 5




                                                      None can be replaced with cmp in sort function
                                                      – Jonas Ausevicius
                                                      Nov 15 at 10:14










                                                    • The [::-1] can be exchanged for a double negation, I think.
                                                      – DonQuiKong
                                                      Nov 16 at 9:30










                                                    • @DonQuiKong that would be quite a bit longer though, as the digits are all strings, and would need to be converted to ints for this.
                                                      – ovs
                                                      Nov 17 at 14:05










                                                    • @JonasAusevicius Thanks a lot.
                                                      – ovs
                                                      Nov 17 at 14:12














                                                    • 5




                                                      None can be replaced with cmp in sort function
                                                      – Jonas Ausevicius
                                                      Nov 15 at 10:14










                                                    • The [::-1] can be exchanged for a double negation, I think.
                                                      – DonQuiKong
                                                      Nov 16 at 9:30










                                                    • @DonQuiKong that would be quite a bit longer though, as the digits are all strings, and would need to be converted to ints for this.
                                                      – ovs
                                                      Nov 17 at 14:05










                                                    • @JonasAusevicius Thanks a lot.
                                                      – ovs
                                                      Nov 17 at 14:12








                                                    5




                                                    5




                                                    None can be replaced with cmp in sort function
                                                    – Jonas Ausevicius
                                                    Nov 15 at 10:14




                                                    None can be replaced with cmp in sort function
                                                    – Jonas Ausevicius
                                                    Nov 15 at 10:14












                                                    The [::-1] can be exchanged for a double negation, I think.
                                                    – DonQuiKong
                                                    Nov 16 at 9:30




                                                    The [::-1] can be exchanged for a double negation, I think.
                                                    – DonQuiKong
                                                    Nov 16 at 9:30












                                                    @DonQuiKong that would be quite a bit longer though, as the digits are all strings, and would need to be converted to ints for this.
                                                    – ovs
                                                    Nov 17 at 14:05




                                                    @DonQuiKong that would be quite a bit longer though, as the digits are all strings, and would need to be converted to ints for this.
                                                    – ovs
                                                    Nov 17 at 14:05












                                                    @JonasAusevicius Thanks a lot.
                                                    – ovs
                                                    Nov 17 at 14:12




                                                    @JonasAusevicius Thanks a lot.
                                                    – ovs
                                                    Nov 17 at 14:12










                                                    up vote
                                                    5
                                                    down vote














                                                    Python 2, 58 60 bytes



                                                    lambda a:sorted(a,key=lambda x:sorted(set(`x`))[::-1])[::-1]



                                                    Try it online!






                                                    share|improve this answer

























                                                      up vote
                                                      5
                                                      down vote














                                                      Python 2, 58 60 bytes



                                                      lambda a:sorted(a,key=lambda x:sorted(set(`x`))[::-1])[::-1]



                                                      Try it online!






                                                      share|improve this answer























                                                        up vote
                                                        5
                                                        down vote










                                                        up vote
                                                        5
                                                        down vote










                                                        Python 2, 58 60 bytes



                                                        lambda a:sorted(a,key=lambda x:sorted(set(`x`))[::-1])[::-1]



                                                        Try it online!






                                                        share|improve this answer













                                                        Python 2, 58 60 bytes



                                                        lambda a:sorted(a,key=lambda x:sorted(set(`x`))[::-1])[::-1]



                                                        Try it online!







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Nov 15 at 10:02









                                                        Jonas Ausevicius

                                                        1113




                                                        1113






















                                                            up vote
                                                            5
                                                            down vote














                                                            Brachylog, 9 bytes



                                                            {ȧdṫo₁}ᵒ¹


                                                            Note: due to how ordering works in brachylog, it does not work on number correctly. This is fixed by casting the number to a string () at the cost of 1 byte.



                                                            Try it online!






                                                            share|improve this answer



















                                                            • 2




                                                              What do you mean by "Due to how ordering works in brachylog, it does not work as intended."? I've tried all four test cases, and its giving the correct results (unless I accidentally looked past something).
                                                              – Kevin Cruijssen
                                                              Nov 15 at 10:12










                                                            • @KevinCruijssen The (to string) fixes the issue. Ordering digits in a number descending works as follows. Order from smallest to largest then reverse. The problem is that the number 3120 ordered from smallest to largest is 0123 which is equal to 123which reversed is 321and not 3210
                                                              – Kroppeb
                                                              Nov 15 at 11:00






                                                            • 2




                                                              Ah ok, so your current code is working due to the added toString (). As mentioned by @Arnauld, I thought your comment meant your current code doesn't work. It might be better to mention it like: "This could have been 8 bytes by removing the (toString), but unfortunately it does not work as intended due to how ordering works in Brachylog."
                                                              – Kevin Cruijssen
                                                              Nov 15 at 11:12










                                                            • Looking at what I wrote it seems that my brain got distracted midsentence. Fixed it.
                                                              – Kroppeb
                                                              Nov 15 at 11:31















                                                            up vote
                                                            5
                                                            down vote














                                                            Brachylog, 9 bytes



                                                            {ȧdṫo₁}ᵒ¹


                                                            Note: due to how ordering works in brachylog, it does not work on number correctly. This is fixed by casting the number to a string () at the cost of 1 byte.



                                                            Try it online!






                                                            share|improve this answer



















                                                            • 2




                                                              What do you mean by "Due to how ordering works in brachylog, it does not work as intended."? I've tried all four test cases, and its giving the correct results (unless I accidentally looked past something).
                                                              – Kevin Cruijssen
                                                              Nov 15 at 10:12










                                                            • @KevinCruijssen The (to string) fixes the issue. Ordering digits in a number descending works as follows. Order from smallest to largest then reverse. The problem is that the number 3120 ordered from smallest to largest is 0123 which is equal to 123which reversed is 321and not 3210
                                                              – Kroppeb
                                                              Nov 15 at 11:00






                                                            • 2




                                                              Ah ok, so your current code is working due to the added toString (). As mentioned by @Arnauld, I thought your comment meant your current code doesn't work. It might be better to mention it like: "This could have been 8 bytes by removing the (toString), but unfortunately it does not work as intended due to how ordering works in Brachylog."
                                                              – Kevin Cruijssen
                                                              Nov 15 at 11:12










                                                            • Looking at what I wrote it seems that my brain got distracted midsentence. Fixed it.
                                                              – Kroppeb
                                                              Nov 15 at 11:31













                                                            up vote
                                                            5
                                                            down vote










                                                            up vote
                                                            5
                                                            down vote










                                                            Brachylog, 9 bytes



                                                            {ȧdṫo₁}ᵒ¹


                                                            Note: due to how ordering works in brachylog, it does not work on number correctly. This is fixed by casting the number to a string () at the cost of 1 byte.



                                                            Try it online!






                                                            share|improve this answer















                                                            Brachylog, 9 bytes



                                                            {ȧdṫo₁}ᵒ¹


                                                            Note: due to how ordering works in brachylog, it does not work on number correctly. This is fixed by casting the number to a string () at the cost of 1 byte.



                                                            Try it online!







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Nov 15 at 11:30

























                                                            answered Nov 15 at 9:59









                                                            Kroppeb

                                                            1,06628




                                                            1,06628








                                                            • 2




                                                              What do you mean by "Due to how ordering works in brachylog, it does not work as intended."? I've tried all four test cases, and its giving the correct results (unless I accidentally looked past something).
                                                              – Kevin Cruijssen
                                                              Nov 15 at 10:12










                                                            • @KevinCruijssen The (to string) fixes the issue. Ordering digits in a number descending works as follows. Order from smallest to largest then reverse. The problem is that the number 3120 ordered from smallest to largest is 0123 which is equal to 123which reversed is 321and not 3210
                                                              – Kroppeb
                                                              Nov 15 at 11:00






                                                            • 2




                                                              Ah ok, so your current code is working due to the added toString (). As mentioned by @Arnauld, I thought your comment meant your current code doesn't work. It might be better to mention it like: "This could have been 8 bytes by removing the (toString), but unfortunately it does not work as intended due to how ordering works in Brachylog."
                                                              – Kevin Cruijssen
                                                              Nov 15 at 11:12










                                                            • Looking at what I wrote it seems that my brain got distracted midsentence. Fixed it.
                                                              – Kroppeb
                                                              Nov 15 at 11:31














                                                            • 2




                                                              What do you mean by "Due to how ordering works in brachylog, it does not work as intended."? I've tried all four test cases, and its giving the correct results (unless I accidentally looked past something).
                                                              – Kevin Cruijssen
                                                              Nov 15 at 10:12










                                                            • @KevinCruijssen The (to string) fixes the issue. Ordering digits in a number descending works as follows. Order from smallest to largest then reverse. The problem is that the number 3120 ordered from smallest to largest is 0123 which is equal to 123which reversed is 321and not 3210
                                                              – Kroppeb
                                                              Nov 15 at 11:00






                                                            • 2




                                                              Ah ok, so your current code is working due to the added toString (). As mentioned by @Arnauld, I thought your comment meant your current code doesn't work. It might be better to mention it like: "This could have been 8 bytes by removing the (toString), but unfortunately it does not work as intended due to how ordering works in Brachylog."
                                                              – Kevin Cruijssen
                                                              Nov 15 at 11:12










                                                            • Looking at what I wrote it seems that my brain got distracted midsentence. Fixed it.
                                                              – Kroppeb
                                                              Nov 15 at 11:31








                                                            2




                                                            2




                                                            What do you mean by "Due to how ordering works in brachylog, it does not work as intended."? I've tried all four test cases, and its giving the correct results (unless I accidentally looked past something).
                                                            – Kevin Cruijssen
                                                            Nov 15 at 10:12




                                                            What do you mean by "Due to how ordering works in brachylog, it does not work as intended."? I've tried all four test cases, and its giving the correct results (unless I accidentally looked past something).
                                                            – Kevin Cruijssen
                                                            Nov 15 at 10:12












                                                            @KevinCruijssen The (to string) fixes the issue. Ordering digits in a number descending works as follows. Order from smallest to largest then reverse. The problem is that the number 3120 ordered from smallest to largest is 0123 which is equal to 123which reversed is 321and not 3210
                                                            – Kroppeb
                                                            Nov 15 at 11:00




                                                            @KevinCruijssen The (to string) fixes the issue. Ordering digits in a number descending works as follows. Order from smallest to largest then reverse. The problem is that the number 3120 ordered from smallest to largest is 0123 which is equal to 123which reversed is 321and not 3210
                                                            – Kroppeb
                                                            Nov 15 at 11:00




                                                            2




                                                            2




                                                            Ah ok, so your current code is working due to the added toString (). As mentioned by @Arnauld, I thought your comment meant your current code doesn't work. It might be better to mention it like: "This could have been 8 bytes by removing the (toString), but unfortunately it does not work as intended due to how ordering works in Brachylog."
                                                            – Kevin Cruijssen
                                                            Nov 15 at 11:12




                                                            Ah ok, so your current code is working due to the added toString (). As mentioned by @Arnauld, I thought your comment meant your current code doesn't work. It might be better to mention it like: "This could have been 8 bytes by removing the (toString), but unfortunately it does not work as intended due to how ordering works in Brachylog."
                                                            – Kevin Cruijssen
                                                            Nov 15 at 11:12












                                                            Looking at what I wrote it seems that my brain got distracted midsentence. Fixed it.
                                                            – Kroppeb
                                                            Nov 15 at 11:31




                                                            Looking at what I wrote it seems that my brain got distracted midsentence. Fixed it.
                                                            – Kroppeb
                                                            Nov 15 at 11:31










                                                            up vote
                                                            5
                                                            down vote













                                                            Pyth, 7 6 bytes



                                                            -1 byte by @Sok



                                                            _o_{S`


                                                            Pyth, which uses only printable ASCII, is at a bit of a disadvantage here. Optimally encoded this would be 6*log(95)/log(256) = 4.927 bytes, beating 05AB1E.



                                                            Explained:



                                                             o              Sort the implicit input by lambda N:
                                                            _ reversed
                                                            { uniquified
                                                            S sorted
                                                            ' string representation [of N]
                                                            _ then reverse the result.


                                                            Try it here.






                                                            share|improve this answer



















                                                            • 2




                                                              The trailing N can be left out to save 1 byte - all lambda-type functions infer the presence of the principle lambda variable if any arguments are missing from the end. Examples include m inferring d, f inferring T, u inferring G...
                                                              – Sok
                                                              Nov 15 at 12:08

















                                                            up vote
                                                            5
                                                            down vote













                                                            Pyth, 7 6 bytes



                                                            -1 byte by @Sok



                                                            _o_{S`


                                                            Pyth, which uses only printable ASCII, is at a bit of a disadvantage here. Optimally encoded this would be 6*log(95)/log(256) = 4.927 bytes, beating 05AB1E.



                                                            Explained:



                                                             o              Sort the implicit input by lambda N:
                                                            _ reversed
                                                            { uniquified
                                                            S sorted
                                                            ' string representation [of N]
                                                            _ then reverse the result.


                                                            Try it here.






                                                            share|improve this answer



















                                                            • 2




                                                              The trailing N can be left out to save 1 byte - all lambda-type functions infer the presence of the principle lambda variable if any arguments are missing from the end. Examples include m inferring d, f inferring T, u inferring G...
                                                              – Sok
                                                              Nov 15 at 12:08















                                                            up vote
                                                            5
                                                            down vote










                                                            up vote
                                                            5
                                                            down vote









                                                            Pyth, 7 6 bytes



                                                            -1 byte by @Sok



                                                            _o_{S`


                                                            Pyth, which uses only printable ASCII, is at a bit of a disadvantage here. Optimally encoded this would be 6*log(95)/log(256) = 4.927 bytes, beating 05AB1E.



                                                            Explained:



                                                             o              Sort the implicit input by lambda N:
                                                            _ reversed
                                                            { uniquified
                                                            S sorted
                                                            ' string representation [of N]
                                                            _ then reverse the result.


                                                            Try it here.






                                                            share|improve this answer














                                                            Pyth, 7 6 bytes



                                                            -1 byte by @Sok



                                                            _o_{S`


                                                            Pyth, which uses only printable ASCII, is at a bit of a disadvantage here. Optimally encoded this would be 6*log(95)/log(256) = 4.927 bytes, beating 05AB1E.



                                                            Explained:



                                                             o              Sort the implicit input by lambda N:
                                                            _ reversed
                                                            { uniquified
                                                            S sorted
                                                            ' string representation [of N]
                                                            _ then reverse the result.


                                                            Try it here.







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Nov 15 at 13:00

























                                                            answered Nov 15 at 10:36









                                                            lirtosiast

                                                            15.6k436107




                                                            15.6k436107








                                                            • 2




                                                              The trailing N can be left out to save 1 byte - all lambda-type functions infer the presence of the principle lambda variable if any arguments are missing from the end. Examples include m inferring d, f inferring T, u inferring G...
                                                              – Sok
                                                              Nov 15 at 12:08
















                                                            • 2




                                                              The trailing N can be left out to save 1 byte - all lambda-type functions infer the presence of the principle lambda variable if any arguments are missing from the end. Examples include m inferring d, f inferring T, u inferring G...
                                                              – Sok
                                                              Nov 15 at 12:08










                                                            2




                                                            2




                                                            The trailing N can be left out to save 1 byte - all lambda-type functions infer the presence of the principle lambda variable if any arguments are missing from the end. Examples include m inferring d, f inferring T, u inferring G...
                                                            – Sok
                                                            Nov 15 at 12:08






                                                            The trailing N can be left out to save 1 byte - all lambda-type functions infer the presence of the principle lambda variable if any arguments are missing from the end. Examples include m inferring d, f inferring T, u inferring G...
                                                            – Sok
                                                            Nov 15 at 12:08












                                                            up vote
                                                            4
                                                            down vote














                                                            Jelly, 8 bytes



                                                            ADṢUQµÞU


                                                            Try it online!



                                                            How it works



                                                            ADṢUQµÞU  Main link (monad). Input: integer list
                                                            µÞU Sort by (reversed):
                                                            AD Absolute value converted to decimal digits
                                                            ṢUQ Sort, reverse, take unique values





                                                            share|improve this answer

















                                                            • 2




                                                              I just implemented this then found your post. I went with normal reverses, , rather than the upends, U. Note, however, that you do not need the D since sort, , is implemented with an iterable(z, make_digits=True) call inside. So that was AṢQṚµÞṚ for 7.
                                                              – Jonathan Allan
                                                              Nov 15 at 18:16















                                                            up vote
                                                            4
                                                            down vote














                                                            Jelly, 8 bytes



                                                            ADṢUQµÞU


                                                            Try it online!



                                                            How it works



                                                            ADṢUQµÞU  Main link (monad). Input: integer list
                                                            µÞU Sort by (reversed):
                                                            AD Absolute value converted to decimal digits
                                                            ṢUQ Sort, reverse, take unique values





                                                            share|improve this answer

















                                                            • 2




                                                              I just implemented this then found your post. I went with normal reverses, , rather than the upends, U. Note, however, that you do not need the D since sort, , is implemented with an iterable(z, make_digits=True) call inside. So that was AṢQṚµÞṚ for 7.
                                                              – Jonathan Allan
                                                              Nov 15 at 18:16













                                                            up vote
                                                            4
                                                            down vote










                                                            up vote
                                                            4
                                                            down vote










                                                            Jelly, 8 bytes



                                                            ADṢUQµÞU


                                                            Try it online!



                                                            How it works



                                                            ADṢUQµÞU  Main link (monad). Input: integer list
                                                            µÞU Sort by (reversed):
                                                            AD Absolute value converted to decimal digits
                                                            ṢUQ Sort, reverse, take unique values





                                                            share|improve this answer













                                                            Jelly, 8 bytes



                                                            ADṢUQµÞU


                                                            Try it online!



                                                            How it works



                                                            ADṢUQµÞU  Main link (monad). Input: integer list
                                                            µÞU Sort by (reversed):
                                                            AD Absolute value converted to decimal digits
                                                            ṢUQ Sort, reverse, take unique values






                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Nov 15 at 10:10









                                                            Bubbler

                                                            6,189759




                                                            6,189759








                                                            • 2




                                                              I just implemented this then found your post. I went with normal reverses, , rather than the upends, U. Note, however, that you do not need the D since sort, , is implemented with an iterable(z, make_digits=True) call inside. So that was AṢQṚµÞṚ for 7.
                                                              – Jonathan Allan
                                                              Nov 15 at 18:16














                                                            • 2




                                                              I just implemented this then found your post. I went with normal reverses, , rather than the upends, U. Note, however, that you do not need the D since sort, , is implemented with an iterable(z, make_digits=True) call inside. So that was AṢQṚµÞṚ for 7.
                                                              – Jonathan Allan
                                                              Nov 15 at 18:16








                                                            2




                                                            2




                                                            I just implemented this then found your post. I went with normal reverses, , rather than the upends, U. Note, however, that you do not need the D since sort, , is implemented with an iterable(z, make_digits=True) call inside. So that was AṢQṚµÞṚ for 7.
                                                            – Jonathan Allan
                                                            Nov 15 at 18:16




                                                            I just implemented this then found your post. I went with normal reverses, , rather than the upends, U. Note, however, that you do not need the D since sort, , is implemented with an iterable(z, make_digits=True) call inside. So that was AṢQṚµÞṚ for 7.
                                                            – Jonathan Allan
                                                            Nov 15 at 18:16










                                                            up vote
                                                            3
                                                            down vote














                                                            MathGolf, 7 6 bytes



                                                            áÉ░▀zx


                                                            Try it online! or as a test suite.



                                                            Explanation



                                                            After looking at Emigna's 05AB1E solution, I found that I didn't need the absolute operator (and my previous answer was actually incorrect because of that operator). Now the main difference is that I convert to string and get unique characters instead of using the 1-byte operator in 05AB1E.



                                                            áÉ      Sort by the value generated from mapping each element using the next 3 instructions
                                                            ░ Convert to string
                                                            ▀ Get unique characters
                                                            z Sort reversed (last instruction of block)
                                                            x Reverse list (needed because I don't have a sort-reversed by mapping)





                                                            share|improve this answer



























                                                              up vote
                                                              3
                                                              down vote














                                                              MathGolf, 7 6 bytes



                                                              áÉ░▀zx


                                                              Try it online! or as a test suite.



                                                              Explanation



                                                              After looking at Emigna's 05AB1E solution, I found that I didn't need the absolute operator (and my previous answer was actually incorrect because of that operator). Now the main difference is that I convert to string and get unique characters instead of using the 1-byte operator in 05AB1E.



                                                              áÉ      Sort by the value generated from mapping each element using the next 3 instructions
                                                              ░ Convert to string
                                                              ▀ Get unique characters
                                                              z Sort reversed (last instruction of block)
                                                              x Reverse list (needed because I don't have a sort-reversed by mapping)





                                                              share|improve this answer

























                                                                up vote
                                                                3
                                                                down vote










                                                                up vote
                                                                3
                                                                down vote










                                                                MathGolf, 7 6 bytes



                                                                áÉ░▀zx


                                                                Try it online! or as a test suite.



                                                                Explanation



                                                                After looking at Emigna's 05AB1E solution, I found that I didn't need the absolute operator (and my previous answer was actually incorrect because of that operator). Now the main difference is that I convert to string and get unique characters instead of using the 1-byte operator in 05AB1E.



                                                                áÉ      Sort by the value generated from mapping each element using the next 3 instructions
                                                                ░ Convert to string
                                                                ▀ Get unique characters
                                                                z Sort reversed (last instruction of block)
                                                                x Reverse list (needed because I don't have a sort-reversed by mapping)





                                                                share|improve this answer















                                                                MathGolf, 7 6 bytes



                                                                áÉ░▀zx


                                                                Try it online! or as a test suite.



                                                                Explanation



                                                                After looking at Emigna's 05AB1E solution, I found that I didn't need the absolute operator (and my previous answer was actually incorrect because of that operator). Now the main difference is that I convert to string and get unique characters instead of using the 1-byte operator in 05AB1E.



                                                                áÉ      Sort by the value generated from mapping each element using the next 3 instructions
                                                                ░ Convert to string
                                                                ▀ Get unique characters
                                                                z Sort reversed (last instruction of block)
                                                                x Reverse list (needed because I don't have a sort-reversed by mapping)






                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited Nov 15 at 11:46

























                                                                answered Nov 15 at 10:19









                                                                maxb

                                                                2,5131927




                                                                2,5131927






















                                                                    up vote
                                                                    3
                                                                    down vote














                                                                    Japt, 12 bytes



                                                                    ñ_a ì â ñnÃw


                                                                    All test cases



                                                                    Explanation:



                                                                    ñ_        Ãw    :Sort Descending by:
                                                                    a : Get the absolute value
                                                                    ì : Get the digits
                                                                    â : Remove duplicates
                                                                    ñn : Sort the digits in descending order





                                                                    share|improve this answer



























                                                                      up vote
                                                                      3
                                                                      down vote














                                                                      Japt, 12 bytes



                                                                      ñ_a ì â ñnÃw


                                                                      All test cases



                                                                      Explanation:



                                                                      ñ_        Ãw    :Sort Descending by:
                                                                      a : Get the absolute value
                                                                      ì : Get the digits
                                                                      â : Remove duplicates
                                                                      ñn : Sort the digits in descending order





                                                                      share|improve this answer

























                                                                        up vote
                                                                        3
                                                                        down vote










                                                                        up vote
                                                                        3
                                                                        down vote










                                                                        Japt, 12 bytes



                                                                        ñ_a ì â ñnÃw


                                                                        All test cases



                                                                        Explanation:



                                                                        ñ_        Ãw    :Sort Descending by:
                                                                        a : Get the absolute value
                                                                        ì : Get the digits
                                                                        â : Remove duplicates
                                                                        ñn : Sort the digits in descending order





                                                                        share|improve this answer















                                                                        Japt, 12 bytes



                                                                        ñ_a ì â ñnÃw


                                                                        All test cases



                                                                        Explanation:



                                                                        ñ_        Ãw    :Sort Descending by:
                                                                        a : Get the absolute value
                                                                        ì : Get the digits
                                                                        â : Remove duplicates
                                                                        ñn : Sort the digits in descending order






                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited Nov 15 at 18:01

























                                                                        answered Nov 15 at 14:59









                                                                        Kamil Drakari

                                                                        2,861416




                                                                        2,861416






















                                                                            up vote
                                                                            3
                                                                            down vote














                                                                            Haskell, 54 52 bytes





                                                                            import Data.List
                                                                            f=r.sortOn(r.sort.nub.show);r=reverse


                                                                            Try it online!






                                                                            share|improve this answer























                                                                            • Defining r=reverse saves two bytes. We also allow anonymous functions, so the f= does not need to ve counted.
                                                                              – Laikoni
                                                                              Nov 15 at 23:33










                                                                            • I moved the import and f= to the TIO header. Is that OK?
                                                                              – Martin Lütke
                                                                              Nov 15 at 23:34










                                                                            • Same byte count, but maybe of some interest: f=r$r id.nub.show;r=(reverse.).sortOn.
                                                                              – Laikoni
                                                                              Nov 15 at 23:43






                                                                            • 1




                                                                              The import actually needs to be counted.
                                                                              – Laikoni
                                                                              Nov 15 at 23:45






                                                                            • 2




                                                                              You may want to have a look at our Guide to golfing rules in Haskell.
                                                                              – Laikoni
                                                                              Nov 15 at 23:52















                                                                            up vote
                                                                            3
                                                                            down vote














                                                                            Haskell, 54 52 bytes





                                                                            import Data.List
                                                                            f=r.sortOn(r.sort.nub.show);r=reverse


                                                                            Try it online!






                                                                            share|improve this answer























                                                                            • Defining r=reverse saves two bytes. We also allow anonymous functions, so the f= does not need to ve counted.
                                                                              – Laikoni
                                                                              Nov 15 at 23:33










                                                                            • I moved the import and f= to the TIO header. Is that OK?
                                                                              – Martin Lütke
                                                                              Nov 15 at 23:34










                                                                            • Same byte count, but maybe of some interest: f=r$r id.nub.show;r=(reverse.).sortOn.
                                                                              – Laikoni
                                                                              Nov 15 at 23:43






                                                                            • 1




                                                                              The import actually needs to be counted.
                                                                              – Laikoni
                                                                              Nov 15 at 23:45






                                                                            • 2




                                                                              You may want to have a look at our Guide to golfing rules in Haskell.
                                                                              – Laikoni
                                                                              Nov 15 at 23:52













                                                                            up vote
                                                                            3
                                                                            down vote










                                                                            up vote
                                                                            3
                                                                            down vote










                                                                            Haskell, 54 52 bytes





                                                                            import Data.List
                                                                            f=r.sortOn(r.sort.nub.show);r=reverse


                                                                            Try it online!






                                                                            share|improve this answer















                                                                            Haskell, 54 52 bytes





                                                                            import Data.List
                                                                            f=r.sortOn(r.sort.nub.show);r=reverse


                                                                            Try it online!







                                                                            share|improve this answer














                                                                            share|improve this answer



                                                                            share|improve this answer








                                                                            edited Nov 16 at 0:09

























                                                                            answered Nov 15 at 23:21









                                                                            Martin Lütke

                                                                            38125




                                                                            38125












                                                                            • Defining r=reverse saves two bytes. We also allow anonymous functions, so the f= does not need to ve counted.
                                                                              – Laikoni
                                                                              Nov 15 at 23:33










                                                                            • I moved the import and f= to the TIO header. Is that OK?
                                                                              – Martin Lütke
                                                                              Nov 15 at 23:34










                                                                            • Same byte count, but maybe of some interest: f=r$r id.nub.show;r=(reverse.).sortOn.
                                                                              – Laikoni
                                                                              Nov 15 at 23:43






                                                                            • 1




                                                                              The import actually needs to be counted.
                                                                              – Laikoni
                                                                              Nov 15 at 23:45






                                                                            • 2




                                                                              You may want to have a look at our Guide to golfing rules in Haskell.
                                                                              – Laikoni
                                                                              Nov 15 at 23:52


















                                                                            • Defining r=reverse saves two bytes. We also allow anonymous functions, so the f= does not need to ve counted.
                                                                              – Laikoni
                                                                              Nov 15 at 23:33










                                                                            • I moved the import and f= to the TIO header. Is that OK?
                                                                              – Martin Lütke
                                                                              Nov 15 at 23:34










                                                                            • Same byte count, but maybe of some interest: f=r$r id.nub.show;r=(reverse.).sortOn.
                                                                              – Laikoni
                                                                              Nov 15 at 23:43






                                                                            • 1




                                                                              The import actually needs to be counted.
                                                                              – Laikoni
                                                                              Nov 15 at 23:45






                                                                            • 2




                                                                              You may want to have a look at our Guide to golfing rules in Haskell.
                                                                              – Laikoni
                                                                              Nov 15 at 23:52
















                                                                            Defining r=reverse saves two bytes. We also allow anonymous functions, so the f= does not need to ve counted.
                                                                            – Laikoni
                                                                            Nov 15 at 23:33




                                                                            Defining r=reverse saves two bytes. We also allow anonymous functions, so the f= does not need to ve counted.
                                                                            – Laikoni
                                                                            Nov 15 at 23:33












                                                                            I moved the import and f= to the TIO header. Is that OK?
                                                                            – Martin Lütke
                                                                            Nov 15 at 23:34




                                                                            I moved the import and f= to the TIO header. Is that OK?
                                                                            – Martin Lütke
                                                                            Nov 15 at 23:34












                                                                            Same byte count, but maybe of some interest: f=r$r id.nub.show;r=(reverse.).sortOn.
                                                                            – Laikoni
                                                                            Nov 15 at 23:43




                                                                            Same byte count, but maybe of some interest: f=r$r id.nub.show;r=(reverse.).sortOn.
                                                                            – Laikoni
                                                                            Nov 15 at 23:43




                                                                            1




                                                                            1




                                                                            The import actually needs to be counted.
                                                                            – Laikoni
                                                                            Nov 15 at 23:45




                                                                            The import actually needs to be counted.
                                                                            – Laikoni
                                                                            Nov 15 at 23:45




                                                                            2




                                                                            2




                                                                            You may want to have a look at our Guide to golfing rules in Haskell.
                                                                            – Laikoni
                                                                            Nov 15 at 23:52




                                                                            You may want to have a look at our Guide to golfing rules in Haskell.
                                                                            – Laikoni
                                                                            Nov 15 at 23:52










                                                                            up vote
                                                                            3
                                                                            down vote














                                                                            Stax, 6 7 bytes



                                                                            èó≥ü≤♥¥


                                                                            Run and debug it






                                                                            share|improve this answer























                                                                            • This seems to give incorrect results. For example, in the test case of your TIO it outputs -904 8491 478 62778 6458 -7738 -73 373 123 3120 0 instead of the intended 8491 -904 62778 478 -7738 6458 373 -73 3120 123 0 or 8491 -904 62778 478 -7738 6458 -73 373 3120 123 0. This test case is also used in the example, and to explain the rules, so I would take a look at that to understand it better. It seems you are only sorting by the single largest digit once, without any of the other rules?
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 7:37












                                                                            • @KevinCruijssen: Yes, my apologies. I mis-read the problem statement. I've adjusted the program to handle the stated requirements. This program is accepting the input integers as quoted strings. That's usually acceptable, but if not I might need to add another byte.
                                                                              – recursive
                                                                              Nov 16 at 17:23










                                                                            • Looks good now, +1 from me. And yes, inputting as strings is completely fine.
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 17:54















                                                                            up vote
                                                                            3
                                                                            down vote














                                                                            Stax, 6 7 bytes



                                                                            èó≥ü≤♥¥


                                                                            Run and debug it






                                                                            share|improve this answer























                                                                            • This seems to give incorrect results. For example, in the test case of your TIO it outputs -904 8491 478 62778 6458 -7738 -73 373 123 3120 0 instead of the intended 8491 -904 62778 478 -7738 6458 373 -73 3120 123 0 or 8491 -904 62778 478 -7738 6458 -73 373 3120 123 0. This test case is also used in the example, and to explain the rules, so I would take a look at that to understand it better. It seems you are only sorting by the single largest digit once, without any of the other rules?
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 7:37












                                                                            • @KevinCruijssen: Yes, my apologies. I mis-read the problem statement. I've adjusted the program to handle the stated requirements. This program is accepting the input integers as quoted strings. That's usually acceptable, but if not I might need to add another byte.
                                                                              – recursive
                                                                              Nov 16 at 17:23










                                                                            • Looks good now, +1 from me. And yes, inputting as strings is completely fine.
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 17:54













                                                                            up vote
                                                                            3
                                                                            down vote










                                                                            up vote
                                                                            3
                                                                            down vote










                                                                            Stax, 6 7 bytes



                                                                            èó≥ü≤♥¥


                                                                            Run and debug it






                                                                            share|improve this answer















                                                                            Stax, 6 7 bytes



                                                                            èó≥ü≤♥¥


                                                                            Run and debug it







                                                                            share|improve this answer














                                                                            share|improve this answer



                                                                            share|improve this answer








                                                                            edited Nov 16 at 17:22

























                                                                            answered Nov 15 at 23:28









                                                                            recursive

                                                                            5,0041221




                                                                            5,0041221












                                                                            • This seems to give incorrect results. For example, in the test case of your TIO it outputs -904 8491 478 62778 6458 -7738 -73 373 123 3120 0 instead of the intended 8491 -904 62778 478 -7738 6458 373 -73 3120 123 0 or 8491 -904 62778 478 -7738 6458 -73 373 3120 123 0. This test case is also used in the example, and to explain the rules, so I would take a look at that to understand it better. It seems you are only sorting by the single largest digit once, without any of the other rules?
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 7:37












                                                                            • @KevinCruijssen: Yes, my apologies. I mis-read the problem statement. I've adjusted the program to handle the stated requirements. This program is accepting the input integers as quoted strings. That's usually acceptable, but if not I might need to add another byte.
                                                                              – recursive
                                                                              Nov 16 at 17:23










                                                                            • Looks good now, +1 from me. And yes, inputting as strings is completely fine.
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 17:54


















                                                                            • This seems to give incorrect results. For example, in the test case of your TIO it outputs -904 8491 478 62778 6458 -7738 -73 373 123 3120 0 instead of the intended 8491 -904 62778 478 -7738 6458 373 -73 3120 123 0 or 8491 -904 62778 478 -7738 6458 -73 373 3120 123 0. This test case is also used in the example, and to explain the rules, so I would take a look at that to understand it better. It seems you are only sorting by the single largest digit once, without any of the other rules?
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 7:37












                                                                            • @KevinCruijssen: Yes, my apologies. I mis-read the problem statement. I've adjusted the program to handle the stated requirements. This program is accepting the input integers as quoted strings. That's usually acceptable, but if not I might need to add another byte.
                                                                              – recursive
                                                                              Nov 16 at 17:23










                                                                            • Looks good now, +1 from me. And yes, inputting as strings is completely fine.
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 17:54
















                                                                            This seems to give incorrect results. For example, in the test case of your TIO it outputs -904 8491 478 62778 6458 -7738 -73 373 123 3120 0 instead of the intended 8491 -904 62778 478 -7738 6458 373 -73 3120 123 0 or 8491 -904 62778 478 -7738 6458 -73 373 3120 123 0. This test case is also used in the example, and to explain the rules, so I would take a look at that to understand it better. It seems you are only sorting by the single largest digit once, without any of the other rules?
                                                                            – Kevin Cruijssen
                                                                            Nov 16 at 7:37






                                                                            This seems to give incorrect results. For example, in the test case of your TIO it outputs -904 8491 478 62778 6458 -7738 -73 373 123 3120 0 instead of the intended 8491 -904 62778 478 -7738 6458 373 -73 3120 123 0 or 8491 -904 62778 478 -7738 6458 -73 373 3120 123 0. This test case is also used in the example, and to explain the rules, so I would take a look at that to understand it better. It seems you are only sorting by the single largest digit once, without any of the other rules?
                                                                            – Kevin Cruijssen
                                                                            Nov 16 at 7:37














                                                                            @KevinCruijssen: Yes, my apologies. I mis-read the problem statement. I've adjusted the program to handle the stated requirements. This program is accepting the input integers as quoted strings. That's usually acceptable, but if not I might need to add another byte.
                                                                            – recursive
                                                                            Nov 16 at 17:23




                                                                            @KevinCruijssen: Yes, my apologies. I mis-read the problem statement. I've adjusted the program to handle the stated requirements. This program is accepting the input integers as quoted strings. That's usually acceptable, but if not I might need to add another byte.
                                                                            – recursive
                                                                            Nov 16 at 17:23












                                                                            Looks good now, +1 from me. And yes, inputting as strings is completely fine.
                                                                            – Kevin Cruijssen
                                                                            Nov 16 at 17:54




                                                                            Looks good now, +1 from me. And yes, inputting as strings is completely fine.
                                                                            – Kevin Cruijssen
                                                                            Nov 16 at 17:54










                                                                            up vote
                                                                            3
                                                                            down vote














                                                                            APL (Dyalog Extended), 19 bytes





                                                                            {⍵[⍒∪¨(∨'¯'~⍨⍕)¨⍵]}


                                                                            Try it online!



                                                                            Fixed at a cost of +2 bytes thanks to OP.






                                                                            share|improve this answer























                                                                            • I think you are missing an 'uniquify' somewhere? If I try the example test case in your TIO for example, ¯7738 is placed before 478, but it should be after it: digits [8,7,4] come before digits [8,7,3].
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 17:52










                                                                            • Thanks, @KevinCruijssen
                                                                              – Zacharý
                                                                              Nov 16 at 21:06















                                                                            up vote
                                                                            3
                                                                            down vote














                                                                            APL (Dyalog Extended), 19 bytes





                                                                            {⍵[⍒∪¨(∨'¯'~⍨⍕)¨⍵]}


                                                                            Try it online!



                                                                            Fixed at a cost of +2 bytes thanks to OP.






                                                                            share|improve this answer























                                                                            • I think you are missing an 'uniquify' somewhere? If I try the example test case in your TIO for example, ¯7738 is placed before 478, but it should be after it: digits [8,7,4] come before digits [8,7,3].
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 17:52










                                                                            • Thanks, @KevinCruijssen
                                                                              – Zacharý
                                                                              Nov 16 at 21:06













                                                                            up vote
                                                                            3
                                                                            down vote










                                                                            up vote
                                                                            3
                                                                            down vote










                                                                            APL (Dyalog Extended), 19 bytes





                                                                            {⍵[⍒∪¨(∨'¯'~⍨⍕)¨⍵]}


                                                                            Try it online!



                                                                            Fixed at a cost of +2 bytes thanks to OP.






                                                                            share|improve this answer















                                                                            APL (Dyalog Extended), 19 bytes





                                                                            {⍵[⍒∪¨(∨'¯'~⍨⍕)¨⍵]}


                                                                            Try it online!



                                                                            Fixed at a cost of +2 bytes thanks to OP.







                                                                            share|improve this answer














                                                                            share|improve this answer



                                                                            share|improve this answer








                                                                            edited Nov 16 at 21:06

























                                                                            answered Nov 16 at 17:01









                                                                            Zacharý

                                                                            5,14511035




                                                                            5,14511035












                                                                            • I think you are missing an 'uniquify' somewhere? If I try the example test case in your TIO for example, ¯7738 is placed before 478, but it should be after it: digits [8,7,4] come before digits [8,7,3].
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 17:52










                                                                            • Thanks, @KevinCruijssen
                                                                              – Zacharý
                                                                              Nov 16 at 21:06


















                                                                            • I think you are missing an 'uniquify' somewhere? If I try the example test case in your TIO for example, ¯7738 is placed before 478, but it should be after it: digits [8,7,4] come before digits [8,7,3].
                                                                              – Kevin Cruijssen
                                                                              Nov 16 at 17:52










                                                                            • Thanks, @KevinCruijssen
                                                                              – Zacharý
                                                                              Nov 16 at 21:06
















                                                                            I think you are missing an 'uniquify' somewhere? If I try the example test case in your TIO for example, ¯7738 is placed before 478, but it should be after it: digits [8,7,4] come before digits [8,7,3].
                                                                            – Kevin Cruijssen
                                                                            Nov 16 at 17:52




                                                                            I think you are missing an 'uniquify' somewhere? If I try the example test case in your TIO for example, ¯7738 is placed before 478, but it should be after it: digits [8,7,4] come before digits [8,7,3].
                                                                            – Kevin Cruijssen
                                                                            Nov 16 at 17:52












                                                                            Thanks, @KevinCruijssen
                                                                            – Zacharý
                                                                            Nov 16 at 21:06




                                                                            Thanks, @KevinCruijssen
                                                                            – Zacharý
                                                                            Nov 16 at 21:06










                                                                            up vote
                                                                            3
                                                                            down vote














                                                                            C (gcc), 114 111 109 bytes





                                                                            a;v(n){n=n<0?-n:n;for(a=0;n;n/=10)a|=1<<n%10;n=a;}c(int*a,int*b){a=v(*a)<v(*b);}f(a,n)int*a;{qsort(a,n,4,c);}


                                                                            Try it online!



                                                                            Explanation:



                                                                            f() uses qsort() to sort provided array in place. Using comparison function c() to compare numbers which evaluates numbers using v().
                                                                            v() calculates a higher number if bigger digits are present in parameter.



                                                                            [Edit 1]
                                                                            Improved by 3 bytes. 2 byte credits to Kevin. Thanks



                                                                            [Edit 2] 2 more bytes improved. Credits to gastropner. Thanks






                                                                            share|improve this answer



















                                                                            • 1




                                                                              You can golf n>0 to n I think in your loop of your method v.
                                                                              – Kevin Cruijssen
                                                                              Nov 15 at 11:55










                                                                            • f()'s argument list int*a,n can be shortened to int*a.
                                                                              – gastropner
                                                                              Nov 19 at 6:58






                                                                            • 1




                                                                              Suggest for(a=0;n=abs(n); instead of n=n<0?-n:n;for(a=0;n;
                                                                              – ceilingcat
                                                                              Nov 20 at 8:31















                                                                            up vote
                                                                            3
                                                                            down vote














                                                                            C (gcc), 114 111 109 bytes





                                                                            a;v(n){n=n<0?-n:n;for(a=0;n;n/=10)a|=1<<n%10;n=a;}c(int*a,int*b){a=v(*a)<v(*b);}f(a,n)int*a;{qsort(a,n,4,c);}


                                                                            Try it online!



                                                                            Explanation:



                                                                            f() uses qsort() to sort provided array in place. Using comparison function c() to compare numbers which evaluates numbers using v().
                                                                            v() calculates a higher number if bigger digits are present in parameter.



                                                                            [Edit 1]
                                                                            Improved by 3 bytes. 2 byte credits to Kevin. Thanks



                                                                            [Edit 2] 2 more bytes improved. Credits to gastropner. Thanks






                                                                            share|improve this answer



















                                                                            • 1




                                                                              You can golf n>0 to n I think in your loop of your method v.
                                                                              – Kevin Cruijssen
                                                                              Nov 15 at 11:55










                                                                            • f()'s argument list int*a,n can be shortened to int*a.
                                                                              – gastropner
                                                                              Nov 19 at 6:58






                                                                            • 1




                                                                              Suggest for(a=0;n=abs(n); instead of n=n<0?-n:n;for(a=0;n;
                                                                              – ceilingcat
                                                                              Nov 20 at 8:31













                                                                            up vote
                                                                            3
                                                                            down vote










                                                                            up vote
                                                                            3
                                                                            down vote










                                                                            C (gcc), 114 111 109 bytes





                                                                            a;v(n){n=n<0?-n:n;for(a=0;n;n/=10)a|=1<<n%10;n=a;}c(int*a,int*b){a=v(*a)<v(*b);}f(a,n)int*a;{qsort(a,n,4,c);}


                                                                            Try it online!



                                                                            Explanation:



                                                                            f() uses qsort() to sort provided array in place. Using comparison function c() to compare numbers which evaluates numbers using v().
                                                                            v() calculates a higher number if bigger digits are present in parameter.



                                                                            [Edit 1]
                                                                            Improved by 3 bytes. 2 byte credits to Kevin. Thanks



                                                                            [Edit 2] 2 more bytes improved. Credits to gastropner. Thanks






                                                                            share|improve this answer















                                                                            C (gcc), 114 111 109 bytes





                                                                            a;v(n){n=n<0?-n:n;for(a=0;n;n/=10)a|=1<<n%10;n=a;}c(int*a,int*b){a=v(*a)<v(*b);}f(a,n)int*a;{qsort(a,n,4,c);}


                                                                            Try it online!



                                                                            Explanation:



                                                                            f() uses qsort() to sort provided array in place. Using comparison function c() to compare numbers which evaluates numbers using v().
                                                                            v() calculates a higher number if bigger digits are present in parameter.



                                                                            [Edit 1]
                                                                            Improved by 3 bytes. 2 byte credits to Kevin. Thanks



                                                                            [Edit 2] 2 more bytes improved. Credits to gastropner. Thanks







                                                                            share|improve this answer














                                                                            share|improve this answer



                                                                            share|improve this answer








                                                                            edited Nov 19 at 14:20

























                                                                            answered Nov 15 at 11:35









                                                                            GPS

                                                                            33115




                                                                            33115








                                                                            • 1




                                                                              You can golf n>0 to n I think in your loop of your method v.
                                                                              – Kevin Cruijssen
                                                                              Nov 15 at 11:55










                                                                            • f()'s argument list int*a,n can be shortened to int*a.
                                                                              – gastropner
                                                                              Nov 19 at 6:58






                                                                            • 1




                                                                              Suggest for(a=0;n=abs(n); instead of n=n<0?-n:n;for(a=0;n;
                                                                              – ceilingcat
                                                                              Nov 20 at 8:31














                                                                            • 1




                                                                              You can golf n>0 to n I think in your loop of your method v.
                                                                              – Kevin Cruijssen
                                                                              Nov 15 at 11:55










                                                                            • f()'s argument list int*a,n can be shortened to int*a.
                                                                              – gastropner
                                                                              Nov 19 at 6:58






                                                                            • 1




                                                                              Suggest for(a=0;n=abs(n); instead of n=n<0?-n:n;for(a=0;n;
                                                                              – ceilingcat
                                                                              Nov 20 at 8:31








                                                                            1




                                                                            1




                                                                            You can golf n>0 to n I think in your loop of your method v.
                                                                            – Kevin Cruijssen
                                                                            Nov 15 at 11:55




                                                                            You can golf n>0 to n I think in your loop of your method v.
                                                                            – Kevin Cruijssen
                                                                            Nov 15 at 11:55












                                                                            f()'s argument list int*a,n can be shortened to int*a.
                                                                            – gastropner
                                                                            Nov 19 at 6:58




                                                                            f()'s argument list int*a,n can be shortened to int*a.
                                                                            – gastropner
                                                                            Nov 19 at 6:58




                                                                            1




                                                                            1




                                                                            Suggest for(a=0;n=abs(n); instead of n=n<0?-n:n;for(a=0;n;
                                                                            – ceilingcat
                                                                            Nov 20 at 8:31




                                                                            Suggest for(a=0;n=abs(n); instead of n=n<0?-n:n;for(a=0;n;
                                                                            – ceilingcat
                                                                            Nov 20 at 8:31










                                                                            up vote
                                                                            2
                                                                            down vote














                                                                            J, 17 bytes



                                                                            {~[::~.@:~@":@|


                                                                            Try it online!



                                                                            Explanation:



                                                                                            @|    - find the absolute value and
                                                                            @": - convert to string and
                                                                            @:~ - sort down and
                                                                            ~. - keep only the unique symbols
                                                                            : - grade down the entire list of strings
                                                                            [: - function composition
                                                                            {~ - use the graded-down list to index into the input





                                                                            share|improve this answer



























                                                                              up vote
                                                                              2
                                                                              down vote














                                                                              J, 17 bytes



                                                                              {~[::~.@:~@":@|


                                                                              Try it online!



                                                                              Explanation:



                                                                                              @|    - find the absolute value and
                                                                              @": - convert to string and
                                                                              @:~ - sort down and
                                                                              ~. - keep only the unique symbols
                                                                              : - grade down the entire list of strings
                                                                              [: - function composition
                                                                              {~ - use the graded-down list to index into the input





                                                                              share|improve this answer

























                                                                                up vote
                                                                                2
                                                                                down vote










                                                                                up vote
                                                                                2
                                                                                down vote










                                                                                J, 17 bytes



                                                                                {~[::~.@:~@":@|


                                                                                Try it online!



                                                                                Explanation:



                                                                                                @|    - find the absolute value and
                                                                                @": - convert to string and
                                                                                @:~ - sort down and
                                                                                ~. - keep only the unique symbols
                                                                                : - grade down the entire list of strings
                                                                                [: - function composition
                                                                                {~ - use the graded-down list to index into the input





                                                                                share|improve this answer















                                                                                J, 17 bytes



                                                                                {~[::~.@:~@":@|


                                                                                Try it online!



                                                                                Explanation:



                                                                                                @|    - find the absolute value and
                                                                                @": - convert to string and
                                                                                @:~ - sort down and
                                                                                ~. - keep only the unique symbols
                                                                                : - grade down the entire list of strings
                                                                                [: - function composition
                                                                                {~ - use the graded-down list to index into the input






                                                                                share|improve this answer














                                                                                share|improve this answer



                                                                                share|improve this answer








                                                                                edited Nov 15 at 12:20

























                                                                                answered Nov 15 at 12:09









                                                                                Galen Ivanov

                                                                                6,11211032




                                                                                6,11211032






















                                                                                    up vote
                                                                                    2
                                                                                    down vote














                                                                                    JavaScript (SpiderMonkey), 68 bytes



                                                                                    Thanks for @Arnauld for reminding me again that SpiderMonkey uses stable sort, so -4 bytes for removing ||-1.





                                                                                    A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y))


                                                                                    Try it online!




                                                                                    JavaScript (Node.js), 72 bytes





                                                                                    A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y)||-1)


                                                                                    Try it online!






                                                                                    share|improve this answer























                                                                                    • Or 68 bytes with SpiderMonkey.
                                                                                      – Arnauld
                                                                                      Nov 15 at 11:04






                                                                                    • 1




                                                                                      @Arnauld oh stable sort again ;P
                                                                                      – Shieru Asakoto
                                                                                      Nov 15 at 12:17










                                                                                    • Actually, I think V8 is using at least 2 different sort algorithms. It seems like it's stable if the size of the array is less than or equal to $10$.
                                                                                      – Arnauld
                                                                                      Nov 15 at 12:37






                                                                                    • 1




                                                                                      @Arnauld V8 use quick sort before Chrome 70. The quick sort algorithm perform an insertion sort when array size is small enough. And latest Chrome had changed to stable sort for matching other browsers' (IE/Firefox/Safari) behavior.
                                                                                      – tsh
                                                                                      Nov 16 at 8:42















                                                                                    up vote
                                                                                    2
                                                                                    down vote














                                                                                    JavaScript (SpiderMonkey), 68 bytes



                                                                                    Thanks for @Arnauld for reminding me again that SpiderMonkey uses stable sort, so -4 bytes for removing ||-1.





                                                                                    A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y))


                                                                                    Try it online!




                                                                                    JavaScript (Node.js), 72 bytes





                                                                                    A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y)||-1)


                                                                                    Try it online!






                                                                                    share|improve this answer























                                                                                    • Or 68 bytes with SpiderMonkey.
                                                                                      – Arnauld
                                                                                      Nov 15 at 11:04






                                                                                    • 1




                                                                                      @Arnauld oh stable sort again ;P
                                                                                      – Shieru Asakoto
                                                                                      Nov 15 at 12:17










                                                                                    • Actually, I think V8 is using at least 2 different sort algorithms. It seems like it's stable if the size of the array is less than or equal to $10$.
                                                                                      – Arnauld
                                                                                      Nov 15 at 12:37






                                                                                    • 1




                                                                                      @Arnauld V8 use quick sort before Chrome 70. The quick sort algorithm perform an insertion sort when array size is small enough. And latest Chrome had changed to stable sort for matching other browsers' (IE/Firefox/Safari) behavior.
                                                                                      – tsh
                                                                                      Nov 16 at 8:42













                                                                                    up vote
                                                                                    2
                                                                                    down vote










                                                                                    up vote
                                                                                    2
                                                                                    down vote










                                                                                    JavaScript (SpiderMonkey), 68 bytes



                                                                                    Thanks for @Arnauld for reminding me again that SpiderMonkey uses stable sort, so -4 bytes for removing ||-1.





                                                                                    A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y))


                                                                                    Try it online!




                                                                                    JavaScript (Node.js), 72 bytes





                                                                                    A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y)||-1)


                                                                                    Try it online!






                                                                                    share|improve this answer















                                                                                    JavaScript (SpiderMonkey), 68 bytes



                                                                                    Thanks for @Arnauld for reminding me again that SpiderMonkey uses stable sort, so -4 bytes for removing ||-1.





                                                                                    A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y))


                                                                                    Try it online!




                                                                                    JavaScript (Node.js), 72 bytes





                                                                                    A=>A.sort((x,y,F=n=>[...new Set(""+n)].sort().reverse())=>F(x)<F(y)||-1)


                                                                                    Try it online!







                                                                                    share|improve this answer














                                                                                    share|improve this answer



                                                                                    share|improve this answer








                                                                                    edited Nov 15 at 12:40

























                                                                                    answered Nov 15 at 10:13









                                                                                    Shieru Asakoto

                                                                                    2,380314




                                                                                    2,380314












                                                                                    • Or 68 bytes with SpiderMonkey.
                                                                                      – Arnauld
                                                                                      Nov 15 at 11:04






                                                                                    • 1




                                                                                      @Arnauld oh stable sort again ;P
                                                                                      – Shieru Asakoto
                                                                                      Nov 15 at 12:17










                                                                                    • Actually, I think V8 is using at least 2 different sort algorithms. It seems like it's stable if the size of the array is less than or equal to $10$.
                                                                                      – Arnauld
                                                                                      Nov 15 at 12:37






                                                                                    • 1




                                                                                      @Arnauld V8 use quick sort before Chrome 70. The quick sort algorithm perform an insertion sort when array size is small enough. And latest Chrome had changed to stable sort for matching other browsers' (IE/Firefox/Safari) behavior.
                                                                                      – tsh
                                                                                      Nov 16 at 8:42


















                                                                                    • Or 68 bytes with SpiderMonkey.
                                                                                      – Arnauld
                                                                                      Nov 15 at 11:04






                                                                                    • 1




                                                                                      @Arnauld oh stable sort again ;P
                                                                                      – Shieru Asakoto
                                                                                      Nov 15 at 12:17










                                                                                    • Actually, I think V8 is using at least 2 different sort algorithms. It seems like it's stable if the size of the array is less than or equal to $10$.
                                                                                      – Arnauld
                                                                                      Nov 15 at 12:37






                                                                                    • 1




                                                                                      @Arnauld V8 use quick sort before Chrome 70. The quick sort algorithm perform an insertion sort when array size is small enough. And latest Chrome had changed to stable sort for matching other browsers' (IE/Firefox/Safari) behavior.
                                                                                      – tsh
                                                                                      Nov 16 at 8:42
















                                                                                    Or 68 bytes with SpiderMonkey.
                                                                                    – Arnauld
                                                                                    Nov 15 at 11:04




                                                                                    Or 68 bytes with SpiderMonkey.
                                                                                    – Arnauld
                                                                                    Nov 15 at 11:04




                                                                                    1




                                                                                    1




                                                                                    @Arnauld oh stable sort again ;P
                                                                                    – Shieru Asakoto
                                                                                    Nov 15 at 12:17




                                                                                    @Arnauld oh stable sort again ;P
                                                                                    – Shieru Asakoto
                                                                                    Nov 15 at 12:17












                                                                                    Actually, I think V8 is using at least 2 different sort algorithms. It seems like it's stable if the size of the array is less than or equal to $10$.
                                                                                    – Arnauld
                                                                                    Nov 15 at 12:37




                                                                                    Actually, I think V8 is using at least 2 different sort algorithms. It seems like it's stable if the size of the array is less than or equal to $10$.
                                                                                    – Arnauld
                                                                                    Nov 15 at 12:37




                                                                                    1




                                                                                    1




                                                                                    @Arnauld V8 use quick sort before Chrome 70. The quick sort algorithm perform an insertion sort when array size is small enough. And latest Chrome had changed to stable sort for matching other browsers' (IE/Firefox/Safari) behavior.
                                                                                    – tsh
                                                                                    Nov 16 at 8:42




                                                                                    @Arnauld V8 use quick sort before Chrome 70. The quick sort algorithm perform an insertion sort when array size is small enough. And latest Chrome had changed to stable sort for matching other browsers' (IE/Firefox/Safari) behavior.
                                                                                    – tsh
                                                                                    Nov 16 at 8:42










                                                                                    up vote
                                                                                    2
                                                                                    down vote














                                                                                    Java (JDK), 98 bytes





                                                                                    l->l.sort((a,b)->{int r=0,i=58;for(;r==0&i-->48;)r=(b.indexOf(i)>>9)-(a.indexOf(i)>>9);return r;})


                                                                                    Try it online!



                                                                                    Explanation



                                                                                    l->                           // Consumer<List<String>>
                                                                                    l.sort( // Use the incorporated sort method which uses a...
                                                                                    (a,b)->{ // Comparator of Strings
                                                                                    int r=0, // define r as the result, initiated to 0
                                                                                    i=58; // i as the codepoint to test for.
                                                                                    for(;r==0&i-->48;) // for each digit codepoint from '9' to '0',
                                                                                    // and while no difference was found.
                                                                                    r= // set r as the difference between
                                                                                    (b.indexOf(i)>>9)- // was the digit found in b? then 0 else -1 using the bit-shift operator
                                                                                    (a.indexOf(i)>>9); // and was the digit found in a? then 0 else -1.
                                                                                    return r; // return the comparison result.
                                                                                    }
                                                                                    )


                                                                                    Note:



                                                                                    I needed a way to map numbers to either 0/1 or 0/-1.



                                                                                    indexOf has the nice property that it's consistently returning -1 for characters not found. -1 right-shifted by any number is always -1. Any positive number right-shifted by a big enough number will always produce 0.



                                                                                    So here we are:



                                                                                    input        input.indexOf('9')      input.indexOf('9')>>9
                                                                                    "999" 0 0
                                                                                    "111119" 5 0
                                                                                    "123456" -1 -1





                                                                                    share|improve this answer



















                                                                                    • 1




                                                                                      Ah, yeah, that's what I mean. ;p Nice golf of using >>9 instead of >>32 due to the limited range of the numbers.
                                                                                      – Kevin Cruijssen
                                                                                      Nov 15 at 12:53















                                                                                    up vote
                                                                                    2
                                                                                    down vote














                                                                                    Java (JDK), 98 bytes





                                                                                    l->l.sort((a,b)->{int r=0,i=58;for(;r==0&i-->48;)r=(b.indexOf(i)>>9)-(a.indexOf(i)>>9);return r;})


                                                                                    Try it online!



                                                                                    Explanation



                                                                                    l->                           // Consumer<List<String>>
                                                                                    l.sort( // Use the incorporated sort method which uses a...
                                                                                    (a,b)->{ // Comparator of Strings
                                                                                    int r=0, // define r as the result, initiated to 0
                                                                                    i=58; // i as the codepoint to test for.
                                                                                    for(;r==0&i-->48;) // for each digit codepoint from '9' to '0',
                                                                                    // and while no difference was found.
                                                                                    r= // set r as the difference between
                                                                                    (b.indexOf(i)>>9)- // was the digit found in b? then 0 else -1 using the bit-shift operator
                                                                                    (a.indexOf(i)>>9); // and was the digit found in a? then 0 else -1.
                                                                                    return r; // return the comparison result.
                                                                                    }
                                                                                    )


                                                                                    Note:



                                                                                    I needed a way to map numbers to either 0/1 or 0/-1.



                                                                                    indexOf has the nice property that it's consistently returning -1 for characters not found. -1 right-shifted by any number is always -1. Any positive number right-shifted by a big enough number will always produce 0.



                                                                                    So here we are:



                                                                                    input        input.indexOf('9')      input.indexOf('9')>>9
                                                                                    "999" 0 0
                                                                                    "111119" 5 0
                                                                                    "123456" -1 -1





                                                                                    share|improve this answer



















                                                                                    • 1




                                                                                      Ah, yeah, that's what I mean. ;p Nice golf of using >>9 instead of >>32 due to the limited range of the numbers.
                                                                                      – Kevin Cruijssen
                                                                                      Nov 15 at 12:53













                                                                                    up vote
                                                                                    2
                                                                                    down vote










                                                                                    up vote
                                                                                    2
                                                                                    down vote










                                                                                    Java (JDK), 98 bytes





                                                                                    l->l.sort((a,b)->{int r=0,i=58;for(;r==0&i-->48;)r=(b.indexOf(i)>>9)-(a.indexOf(i)>>9);return r;})


                                                                                    Try it online!



                                                                                    Explanation



                                                                                    l->                           // Consumer<List<String>>
                                                                                    l.sort( // Use the incorporated sort method which uses a...
                                                                                    (a,b)->{ // Comparator of Strings
                                                                                    int r=0, // define r as the result, initiated to 0
                                                                                    i=58; // i as the codepoint to test for.
                                                                                    for(;r==0&i-->48;) // for each digit codepoint from '9' to '0',
                                                                                    // and while no difference was found.
                                                                                    r= // set r as the difference between
                                                                                    (b.indexOf(i)>>9)- // was the digit found in b? then 0 else -1 using the bit-shift operator
                                                                                    (a.indexOf(i)>>9); // and was the digit found in a? then 0 else -1.
                                                                                    return r; // return the comparison result.
                                                                                    }
                                                                                    )


                                                                                    Note:



                                                                                    I needed a way to map numbers to either 0/1 or 0/-1.



                                                                                    indexOf has the nice property that it's consistently returning -1 for characters not found. -1 right-shifted by any number is always -1. Any positive number right-shifted by a big enough number will always produce 0.



                                                                                    So here we are:



                                                                                    input        input.indexOf('9')      input.indexOf('9')>>9
                                                                                    "999" 0 0
                                                                                    "111119" 5 0
                                                                                    "123456" -1 -1





                                                                                    share|improve this answer















                                                                                    Java (JDK), 98 bytes





                                                                                    l->l.sort((a,b)->{int r=0,i=58;for(;r==0&i-->48;)r=(b.indexOf(i)>>9)-(a.indexOf(i)>>9);return r;})


                                                                                    Try it online!



                                                                                    Explanation



                                                                                    l->                           // Consumer<List<String>>
                                                                                    l.sort( // Use the incorporated sort method which uses a...
                                                                                    (a,b)->{ // Comparator of Strings
                                                                                    int r=0, // define r as the result, initiated to 0
                                                                                    i=58; // i as the codepoint to test for.
                                                                                    for(;r==0&i-->48;) // for each digit codepoint from '9' to '0',
                                                                                    // and while no difference was found.
                                                                                    r= // set r as the difference between
                                                                                    (b.indexOf(i)>>9)- // was the digit found in b? then 0 else -1 using the bit-shift operator
                                                                                    (a.indexOf(i)>>9); // and was the digit found in a? then 0 else -1.
                                                                                    return r; // return the comparison result.
                                                                                    }
                                                                                    )


                                                                                    Note:



                                                                                    I needed a way to map numbers to either 0/1 or 0/-1.



                                                                                    indexOf has the nice property that it's consistently returning -1 for characters not found. -1 right-shifted by any number is always -1. Any positive number right-shifted by a big enough number will always produce 0.



                                                                                    So here we are:



                                                                                    input        input.indexOf('9')      input.indexOf('9')>>9
                                                                                    "999" 0 0
                                                                                    "111119" 5 0
                                                                                    "123456" -1 -1






                                                                                    share|improve this answer














                                                                                    share|improve this answer



                                                                                    share|improve this answer








                                                                                    edited Nov 15 at 13:01

























                                                                                    answered Nov 15 at 12:11









                                                                                    Olivier Grégoire

                                                                                    8,61711843




                                                                                    8,61711843








                                                                                    • 1




                                                                                      Ah, yeah, that's what I mean. ;p Nice golf of using >>9 instead of >>32 due to the limited range of the numbers.
                                                                                      – Kevin Cruijssen
                                                                                      Nov 15 at 12:53














                                                                                    • 1




                                                                                      Ah, yeah, that's what I mean. ;p Nice golf of using >>9 instead of >>32 due to the limited range of the numbers.
                                                                                      – Kevin Cruijssen
                                                                                      Nov 15 at 12:53








                                                                                    1




                                                                                    1




                                                                                    Ah, yeah, that's what I mean. ;p Nice golf of using >>9 instead of >>32 due to the limited range of the numbers.
                                                                                    – Kevin Cruijssen
                                                                                    Nov 15 at 12:53




                                                                                    Ah, yeah, that's what I mean. ;p Nice golf of using >>9 instead of >>32 due to the limited range of the numbers.
                                                                                    – Kevin Cruijssen
                                                                                    Nov 15 at 12:53










                                                                                    up vote
                                                                                    1
                                                                                    down vote














                                                                                    Ruby, 55 bytes





                                                                                    ->a{a.sort_by{|x|x.abs.digits.sort.reverse|}.reverse}


                                                                                    Try it online!






                                                                                    share|improve this answer

























                                                                                      up vote
                                                                                      1
                                                                                      down vote














                                                                                      Ruby, 55 bytes





                                                                                      ->a{a.sort_by{|x|x.abs.digits.sort.reverse|}.reverse}


                                                                                      Try it online!






                                                                                      share|improve this answer























                                                                                        up vote
                                                                                        1
                                                                                        down vote










                                                                                        up vote
                                                                                        1
                                                                                        down vote










                                                                                        Ruby, 55 bytes





                                                                                        ->a{a.sort_by{|x|x.abs.digits.sort.reverse|}.reverse}


                                                                                        Try it online!






                                                                                        share|improve this answer













                                                                                        Ruby, 55 bytes





                                                                                        ->a{a.sort_by{|x|x.abs.digits.sort.reverse|}.reverse}


                                                                                        Try it online!







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Nov 15 at 14:29









                                                                                        Kirill L.

                                                                                        3,4751218




                                                                                        3,4751218






















                                                                                            up vote
                                                                                            1
                                                                                            down vote














                                                                                            Perl 5 -nl, 68 bytes





                                                                                            $a{eval"9876543210=~y/$_//dcr"}=$_}{say$a{$_}for reverse sort keys%a


                                                                                            Try it online!






                                                                                            share|improve this answer

























                                                                                              up vote
                                                                                              1
                                                                                              down vote














                                                                                              Perl 5 -nl, 68 bytes





                                                                                              $a{eval"9876543210=~y/$_//dcr"}=$_}{say$a{$_}for reverse sort keys%a


                                                                                              Try it online!






                                                                                              share|improve this answer























                                                                                                up vote
                                                                                                1
                                                                                                down vote










                                                                                                up vote
                                                                                                1
                                                                                                down vote










                                                                                                Perl 5 -nl, 68 bytes





                                                                                                $a{eval"9876543210=~y/$_//dcr"}=$_}{say$a{$_}for reverse sort keys%a


                                                                                                Try it online!






                                                                                                share|improve this answer













                                                                                                Perl 5 -nl, 68 bytes





                                                                                                $a{eval"9876543210=~y/$_//dcr"}=$_}{say$a{$_}for reverse sort keys%a


                                                                                                Try it online!







                                                                                                share|improve this answer












                                                                                                share|improve this answer



                                                                                                share|improve this answer










                                                                                                answered Nov 15 at 19:22









                                                                                                Xcali

                                                                                                5,059520




                                                                                                5,059520






















                                                                                                    up vote
                                                                                                    1
                                                                                                    down vote














                                                                                                    Julia 1.0, 50 bytes





                                                                                                    x->sort(x,by=y->sort(unique([digits(-abs(y));1])))


                                                                                                    Try it online!






                                                                                                    share|improve this answer

























                                                                                                      up vote
                                                                                                      1
                                                                                                      down vote














                                                                                                      Julia 1.0, 50 bytes





                                                                                                      x->sort(x,by=y->sort(unique([digits(-abs(y));1])))


                                                                                                      Try it online!






                                                                                                      share|improve this answer























                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote










                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote










                                                                                                        Julia 1.0, 50 bytes





                                                                                                        x->sort(x,by=y->sort(unique([digits(-abs(y));1])))


                                                                                                        Try it online!






                                                                                                        share|improve this answer













                                                                                                        Julia 1.0, 50 bytes





                                                                                                        x->sort(x,by=y->sort(unique([digits(-abs(y));1])))


                                                                                                        Try it online!







                                                                                                        share|improve this answer












                                                                                                        share|improve this answer



                                                                                                        share|improve this answer










                                                                                                        answered Nov 16 at 14:34









                                                                                                        Kirill L.

                                                                                                        3,4751218




                                                                                                        3,4751218






















                                                                                                            up vote
                                                                                                            1
                                                                                                            down vote













                                                                                                            APL(NARS), 366 chars, 732 bytes



                                                                                                            _gb←⍬

                                                                                                            ∇a _s w;t
                                                                                                            t←_gb[a]⋄_gb[a]←_gb[w]⋄_gb[w]←t


                                                                                                            ∇(_f _q)w;l;r;ls;i
                                                                                                            (l r)←w⋄→0×⍳l≥r⋄l _s⌊2÷⍨l+r⋄ls←i←l⋄→3
                                                                                                            →3×⍳∼0<_gb[i]_f _gb[l]⋄ls+←1⋄ls _s i
                                                                                                            →2×⍳r≥i+←1
                                                                                                            l _s ls⋄_f _q l(ls-1)⋄_f _q(ls+1)r


                                                                                                            ∇r←(a qsort)w
                                                                                                            r←¯1⋄→0×⍳1≠⍴⍴w⋄_gb←w⋄a _q 1(↑⍴w)⋄r←_gb


                                                                                                            f←{∪t[⍒t←⍎¨⍕∣⍵]}

                                                                                                            ∇r←a c b;x;y;i;m
                                                                                                            x←f a⋄y←f b⋄r←i←0⋄m←(↑⍴x)⌊(↑⍴y)⋄→3
                                                                                                            →0×⍳x[i]<y[i]⋄→3×⍳∼x[i]>y[i]⋄r←1⋄→0
                                                                                                            →2×⍳m≥i+←1⋄r←(↑⍴x)>(↑⍴y)



                                                                                                            For the qsort operator, it is one traslation in APL of algo page 139 K&R Linguaggio C.
                                                                                                            I think in it there is using data as C with pointers...
                                                                                                            Test



                                                                                                             c qsort 123, 478, ¯904, 62778, 0, ¯73, 8491, 3120, 6458, ¯7738, 373 
                                                                                                            8491 ¯904 62778 478 ¯7738 6458 ¯73 373 3120 123 0
                                                                                                            c qsort 11, ¯312, 902, 23, 321, 2132, 34202, ¯34, ¯382
                                                                                                            902 ¯382 34202 ¯34 321 ¯312 2132 23 11
                                                                                                            c qsort 9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0
                                                                                                            29384 192 9 6 6 4 44 2212 21 2 1 0
                                                                                                            c qsort 44, ¯88, 9, 233, ¯3, 14, 101, 77, 555, 67
                                                                                                            9 ¯88 67 77 555 14 44 233 ¯3 101





                                                                                                            share|improve this answer

























                                                                                                              up vote
                                                                                                              1
                                                                                                              down vote













                                                                                                              APL(NARS), 366 chars, 732 bytes



                                                                                                              _gb←⍬

                                                                                                              ∇a _s w;t
                                                                                                              t←_gb[a]⋄_gb[a]←_gb[w]⋄_gb[w]←t


                                                                                                              ∇(_f _q)w;l;r;ls;i
                                                                                                              (l r)←w⋄→0×⍳l≥r⋄l _s⌊2÷⍨l+r⋄ls←i←l⋄→3
                                                                                                              →3×⍳∼0<_gb[i]_f _gb[l]⋄ls+←1⋄ls _s i
                                                                                                              →2×⍳r≥i+←1
                                                                                                              l _s ls⋄_f _q l(ls-1)⋄_f _q(ls+1)r


                                                                                                              ∇r←(a qsort)w
                                                                                                              r←¯1⋄→0×⍳1≠⍴⍴w⋄_gb←w⋄a _q 1(↑⍴w)⋄r←_gb


                                                                                                              f←{∪t[⍒t←⍎¨⍕∣⍵]}

                                                                                                              ∇r←a c b;x;y;i;m
                                                                                                              x←f a⋄y←f b⋄r←i←0⋄m←(↑⍴x)⌊(↑⍴y)⋄→3
                                                                                                              →0×⍳x[i]<y[i]⋄→3×⍳∼x[i]>y[i]⋄r←1⋄→0
                                                                                                              →2×⍳m≥i+←1⋄r←(↑⍴x)>(↑⍴y)



                                                                                                              For the qsort operator, it is one traslation in APL of algo page 139 K&R Linguaggio C.
                                                                                                              I think in it there is using data as C with pointers...
                                                                                                              Test



                                                                                                               c qsort 123, 478, ¯904, 62778, 0, ¯73, 8491, 3120, 6458, ¯7738, 373 
                                                                                                              8491 ¯904 62778 478 ¯7738 6458 ¯73 373 3120 123 0
                                                                                                              c qsort 11, ¯312, 902, 23, 321, 2132, 34202, ¯34, ¯382
                                                                                                              902 ¯382 34202 ¯34 321 ¯312 2132 23 11
                                                                                                              c qsort 9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0
                                                                                                              29384 192 9 6 6 4 44 2212 21 2 1 0
                                                                                                              c qsort 44, ¯88, 9, 233, ¯3, 14, 101, 77, 555, 67
                                                                                                              9 ¯88 67 77 555 14 44 233 ¯3 101





                                                                                                              share|improve this answer























                                                                                                                up vote
                                                                                                                1
                                                                                                                down vote










                                                                                                                up vote
                                                                                                                1
                                                                                                                down vote









                                                                                                                APL(NARS), 366 chars, 732 bytes



                                                                                                                _gb←⍬

                                                                                                                ∇a _s w;t
                                                                                                                t←_gb[a]⋄_gb[a]←_gb[w]⋄_gb[w]←t


                                                                                                                ∇(_f _q)w;l;r;ls;i
                                                                                                                (l r)←w⋄→0×⍳l≥r⋄l _s⌊2÷⍨l+r⋄ls←i←l⋄→3
                                                                                                                →3×⍳∼0<_gb[i]_f _gb[l]⋄ls+←1⋄ls _s i
                                                                                                                →2×⍳r≥i+←1
                                                                                                                l _s ls⋄_f _q l(ls-1)⋄_f _q(ls+1)r


                                                                                                                ∇r←(a qsort)w
                                                                                                                r←¯1⋄→0×⍳1≠⍴⍴w⋄_gb←w⋄a _q 1(↑⍴w)⋄r←_gb


                                                                                                                f←{∪t[⍒t←⍎¨⍕∣⍵]}

                                                                                                                ∇r←a c b;x;y;i;m
                                                                                                                x←f a⋄y←f b⋄r←i←0⋄m←(↑⍴x)⌊(↑⍴y)⋄→3
                                                                                                                →0×⍳x[i]<y[i]⋄→3×⍳∼x[i]>y[i]⋄r←1⋄→0
                                                                                                                →2×⍳m≥i+←1⋄r←(↑⍴x)>(↑⍴y)



                                                                                                                For the qsort operator, it is one traslation in APL of algo page 139 K&R Linguaggio C.
                                                                                                                I think in it there is using data as C with pointers...
                                                                                                                Test



                                                                                                                 c qsort 123, 478, ¯904, 62778, 0, ¯73, 8491, 3120, 6458, ¯7738, 373 
                                                                                                                8491 ¯904 62778 478 ¯7738 6458 ¯73 373 3120 123 0
                                                                                                                c qsort 11, ¯312, 902, 23, 321, 2132, 34202, ¯34, ¯382
                                                                                                                902 ¯382 34202 ¯34 321 ¯312 2132 23 11
                                                                                                                c qsort 9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0
                                                                                                                29384 192 9 6 6 4 44 2212 21 2 1 0
                                                                                                                c qsort 44, ¯88, 9, 233, ¯3, 14, 101, 77, 555, 67
                                                                                                                9 ¯88 67 77 555 14 44 233 ¯3 101





                                                                                                                share|improve this answer












                                                                                                                APL(NARS), 366 chars, 732 bytes



                                                                                                                _gb←⍬

                                                                                                                ∇a _s w;t
                                                                                                                t←_gb[a]⋄_gb[a]←_gb[w]⋄_gb[w]←t


                                                                                                                ∇(_f _q)w;l;r;ls;i
                                                                                                                (l r)←w⋄→0×⍳l≥r⋄l _s⌊2÷⍨l+r⋄ls←i←l⋄→3
                                                                                                                →3×⍳∼0<_gb[i]_f _gb[l]⋄ls+←1⋄ls _s i
                                                                                                                →2×⍳r≥i+←1
                                                                                                                l _s ls⋄_f _q l(ls-1)⋄_f _q(ls+1)r


                                                                                                                ∇r←(a qsort)w
                                                                                                                r←¯1⋄→0×⍳1≠⍴⍴w⋄_gb←w⋄a _q 1(↑⍴w)⋄r←_gb


                                                                                                                f←{∪t[⍒t←⍎¨⍕∣⍵]}

                                                                                                                ∇r←a c b;x;y;i;m
                                                                                                                x←f a⋄y←f b⋄r←i←0⋄m←(↑⍴x)⌊(↑⍴y)⋄→3
                                                                                                                →0×⍳x[i]<y[i]⋄→3×⍳∼x[i]>y[i]⋄r←1⋄→0
                                                                                                                →2×⍳m≥i+←1⋄r←(↑⍴x)>(↑⍴y)



                                                                                                                For the qsort operator, it is one traslation in APL of algo page 139 K&R Linguaggio C.
                                                                                                                I think in it there is using data as C with pointers...
                                                                                                                Test



                                                                                                                 c qsort 123, 478, ¯904, 62778, 0, ¯73, 8491, 3120, 6458, ¯7738, 373 
                                                                                                                8491 ¯904 62778 478 ¯7738 6458 ¯73 373 3120 123 0
                                                                                                                c qsort 11, ¯312, 902, 23, 321, 2132, 34202, ¯34, ¯382
                                                                                                                902 ¯382 34202 ¯34 321 ¯312 2132 23 11
                                                                                                                c qsort 9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0
                                                                                                                29384 192 9 6 6 4 44 2212 21 2 1 0
                                                                                                                c qsort 44, ¯88, 9, 233, ¯3, 14, 101, 77, 555, 67
                                                                                                                9 ¯88 67 77 555 14 44 233 ¯3 101






                                                                                                                share|improve this answer












                                                                                                                share|improve this answer



                                                                                                                share|improve this answer










                                                                                                                answered Nov 17 at 10:48









                                                                                                                RosLuP

                                                                                                                1,768514




                                                                                                                1,768514






















                                                                                                                    up vote
                                                                                                                    1
                                                                                                                    down vote













                                                                                                                    Powershell, 44 bytes





                                                                                                                    $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d


                                                                                                                    Test script:



                                                                                                                    $f = {

                                                                                                                    $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d

                                                                                                                    }

                                                                                                                    @(
                                                                                                                    ,( (123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373),
                                                                                                                    (8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0),
                                                                                                                    (8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0) )

                                                                                                                    ,( (11, -312, 902, 23, 321, 2132, 34202, -34, -382),
                                                                                                                    (902, -382, 34202, -34, -312, 321, 2132, 23, 11),
                                                                                                                    (902, -382, 34202, -34, 2132, -312, 321, 23, 11) )

                                                                                                                    ,( (9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0),
                                                                                                                    (29384, 192, 9, 6, 6, 4, 44, 2212, 21, 2, 1, 0),
                                                                                                                    (29384, 192, 9, 6, 6, 44, 4, 2212, 21, 2, 1, 0),
                                                                                                                    (29384, 192, 9, 6, 6, 44, 4, 21, 2212, 2, 1, 0) )

                                                                                                                    ,( (44, -88, 9, 233, -3, 14, 101, 77, 555, 67),
                                                                                                                    ,(9, -88, 67, 77, 555, 14, 44, 233, -3, 101) )
                                                                                                                    ) | % {
                                                                                                                    $a, $expected = $_
                                                                                                                    $result = &$f @a
                                                                                                                    $true-in($expected|%{"$result"-eq"$_"})
                                                                                                                    "$result"
                                                                                                                    }


                                                                                                                    Output:



                                                                                                                    True
                                                                                                                    8491 -904 62778 478 -7738 6458 -73 373 3120 123 0
                                                                                                                    True
                                                                                                                    902 -382 34202 -34 2132 -312 321 23 11
                                                                                                                    True
                                                                                                                    29384 192 9 6 6 44 4 21 2212 2 1 0
                                                                                                                    True
                                                                                                                    9 -88 67 77 555 14 44 233 -3 101





                                                                                                                    share|improve this answer

























                                                                                                                      up vote
                                                                                                                      1
                                                                                                                      down vote













                                                                                                                      Powershell, 44 bytes





                                                                                                                      $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d


                                                                                                                      Test script:



                                                                                                                      $f = {

                                                                                                                      $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d

                                                                                                                      }

                                                                                                                      @(
                                                                                                                      ,( (123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373),
                                                                                                                      (8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0),
                                                                                                                      (8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0) )

                                                                                                                      ,( (11, -312, 902, 23, 321, 2132, 34202, -34, -382),
                                                                                                                      (902, -382, 34202, -34, -312, 321, 2132, 23, 11),
                                                                                                                      (902, -382, 34202, -34, 2132, -312, 321, 23, 11) )

                                                                                                                      ,( (9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0),
                                                                                                                      (29384, 192, 9, 6, 6, 4, 44, 2212, 21, 2, 1, 0),
                                                                                                                      (29384, 192, 9, 6, 6, 44, 4, 2212, 21, 2, 1, 0),
                                                                                                                      (29384, 192, 9, 6, 6, 44, 4, 21, 2212, 2, 1, 0) )

                                                                                                                      ,( (44, -88, 9, 233, -3, 14, 101, 77, 555, 67),
                                                                                                                      ,(9, -88, 67, 77, 555, 14, 44, 233, -3, 101) )
                                                                                                                      ) | % {
                                                                                                                      $a, $expected = $_
                                                                                                                      $result = &$f @a
                                                                                                                      $true-in($expected|%{"$result"-eq"$_"})
                                                                                                                      "$result"
                                                                                                                      }


                                                                                                                      Output:



                                                                                                                      True
                                                                                                                      8491 -904 62778 478 -7738 6458 -73 373 3120 123 0
                                                                                                                      True
                                                                                                                      902 -382 34202 -34 2132 -312 321 23 11
                                                                                                                      True
                                                                                                                      29384 192 9 6 6 44 4 21 2212 2 1 0
                                                                                                                      True
                                                                                                                      9 -88 67 77 555 14 44 233 -3 101





                                                                                                                      share|improve this answer























                                                                                                                        up vote
                                                                                                                        1
                                                                                                                        down vote










                                                                                                                        up vote
                                                                                                                        1
                                                                                                                        down vote









                                                                                                                        Powershell, 44 bytes





                                                                                                                        $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d


                                                                                                                        Test script:



                                                                                                                        $f = {

                                                                                                                        $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d

                                                                                                                        }

                                                                                                                        @(
                                                                                                                        ,( (123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373),
                                                                                                                        (8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0),
                                                                                                                        (8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0) )

                                                                                                                        ,( (11, -312, 902, 23, 321, 2132, 34202, -34, -382),
                                                                                                                        (902, -382, 34202, -34, -312, 321, 2132, 23, 11),
                                                                                                                        (902, -382, 34202, -34, 2132, -312, 321, 23, 11) )

                                                                                                                        ,( (9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0),
                                                                                                                        (29384, 192, 9, 6, 6, 4, 44, 2212, 21, 2, 1, 0),
                                                                                                                        (29384, 192, 9, 6, 6, 44, 4, 2212, 21, 2, 1, 0),
                                                                                                                        (29384, 192, 9, 6, 6, 44, 4, 21, 2212, 2, 1, 0) )

                                                                                                                        ,( (44, -88, 9, 233, -3, 14, 101, 77, 555, 67),
                                                                                                                        ,(9, -88, 67, 77, 555, 14, 44, 233, -3, 101) )
                                                                                                                        ) | % {
                                                                                                                        $a, $expected = $_
                                                                                                                        $result = &$f @a
                                                                                                                        $true-in($expected|%{"$result"-eq"$_"})
                                                                                                                        "$result"
                                                                                                                        }


                                                                                                                        Output:



                                                                                                                        True
                                                                                                                        8491 -904 62778 478 -7738 6458 -73 373 3120 123 0
                                                                                                                        True
                                                                                                                        902 -382 34202 -34 2132 -312 321 23 11
                                                                                                                        True
                                                                                                                        29384 192 9 6 6 44 4 21 2212 2 1 0
                                                                                                                        True
                                                                                                                        9 -88 67 77 555 14 44 233 -3 101





                                                                                                                        share|improve this answer












                                                                                                                        Powershell, 44 bytes





                                                                                                                        $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d


                                                                                                                        Test script:



                                                                                                                        $f = {

                                                                                                                        $args|sort{$_-split'(.)'-ne'-'|sort -u -d}-d

                                                                                                                        }

                                                                                                                        @(
                                                                                                                        ,( (123, 478, -904, 62778, 0, -73, 8491, 3120, 6458, -7738, 373),
                                                                                                                        (8491, -904, 62778, 478, -7738, 6458, 373, -73, 3120, 123, 0),
                                                                                                                        (8491, -904, 62778, 478, -7738, 6458, -73, 373, 3120, 123, 0) )

                                                                                                                        ,( (11, -312, 902, 23, 321, 2132, 34202, -34, -382),
                                                                                                                        (902, -382, 34202, -34, -312, 321, 2132, 23, 11),
                                                                                                                        (902, -382, 34202, -34, 2132, -312, 321, 23, 11) )

                                                                                                                        ,( (9, 44, 2212, 4, 6, 6, 1, 2, 192, 21, 29384, 0),
                                                                                                                        (29384, 192, 9, 6, 6, 4, 44, 2212, 21, 2, 1, 0),
                                                                                                                        (29384, 192, 9, 6, 6, 44, 4, 2212, 21, 2, 1, 0),
                                                                                                                        (29384, 192, 9, 6, 6, 44, 4, 21, 2212, 2, 1, 0) )

                                                                                                                        ,( (44, -88, 9, 233, -3, 14, 101, 77, 555, 67),
                                                                                                                        ,(9, -88, 67, 77, 555, 14, 44, 233, -3, 101) )
                                                                                                                        ) | % {
                                                                                                                        $a, $expected = $_
                                                                                                                        $result = &$f @a
                                                                                                                        $true-in($expected|%{"$result"-eq"$_"})
                                                                                                                        "$result"
                                                                                                                        }


                                                                                                                        Output:



                                                                                                                        True
                                                                                                                        8491 -904 62778 478 -7738 6458 -73 373 3120 123 0
                                                                                                                        True
                                                                                                                        902 -382 34202 -34 2132 -312 321 23 11
                                                                                                                        True
                                                                                                                        29384 192 9 6 6 44 4 21 2212 2 1 0
                                                                                                                        True
                                                                                                                        9 -88 67 77 555 14 44 233 -3 101






                                                                                                                        share|improve this answer












                                                                                                                        share|improve this answer



                                                                                                                        share|improve this answer










                                                                                                                        answered Nov 17 at 12:57









                                                                                                                        mazzy

                                                                                                                        1,9851314




                                                                                                                        1,9851314






















                                                                                                                            up vote
                                                                                                                            1
                                                                                                                            down vote













                                                                                                                            PHP, 87 86 84 bytes





                                                                                                                            while(--$argc)$a[_.strrev(count_chars($n=$argv[++$i],3))]=$n;krsort($a);print_r($a);


                                                                                                                            Run with -nr or try it online.



                                                                                                                            Replace ++$i with $argc (+1 byte) to suppress the Notice (and render -n obosolete).



                                                                                                                            breakdown



                                                                                                                            while(--$argc)  # loop through command line arguments
                                                                                                                            $a[ # key=
                                                                                                                            _. # 3. prepend non-numeric char for non-numeric sort
                                                                                                                            strrev( # 2. reverse =^= sort descending
                                                                                                                            count_chars($n=$argv[++$i],3) # 1. get characters used in argument
                                                                                                                            )
                                                                                                                            ]=$n; # value=argument
                                                                                                                            krsort($a); # sort by key descending
                                                                                                                            print_r($a); # print


                                                                                                                            - is "smaller" than the digits, so it has no affect on the sorting.






                                                                                                                            share|improve this answer



























                                                                                                                              up vote
                                                                                                                              1
                                                                                                                              down vote













                                                                                                                              PHP, 87 86 84 bytes





                                                                                                                              while(--$argc)$a[_.strrev(count_chars($n=$argv[++$i],3))]=$n;krsort($a);print_r($a);


                                                                                                                              Run with -nr or try it online.



                                                                                                                              Replace ++$i with $argc (+1 byte) to suppress the Notice (and render -n obosolete).



                                                                                                                              breakdown



                                                                                                                              while(--$argc)  # loop through command line arguments
                                                                                                                              $a[ # key=
                                                                                                                              _. # 3. prepend non-numeric char for non-numeric sort
                                                                                                                              strrev( # 2. reverse =^= sort descending
                                                                                                                              count_chars($n=$argv[++$i],3) # 1. get characters used in argument
                                                                                                                              )
                                                                                                                              ]=$n; # value=argument
                                                                                                                              krsort($a); # sort by key descending
                                                                                                                              print_r($a); # print


                                                                                                                              - is "smaller" than the digits, so it has no affect on the sorting.






                                                                                                                              share|improve this answer

























                                                                                                                                up vote
                                                                                                                                1
                                                                                                                                down vote










                                                                                                                                up vote
                                                                                                                                1
                                                                                                                                down vote









                                                                                                                                PHP, 87 86 84 bytes





                                                                                                                                while(--$argc)$a[_.strrev(count_chars($n=$argv[++$i],3))]=$n;krsort($a);print_r($a);


                                                                                                                                Run with -nr or try it online.



                                                                                                                                Replace ++$i with $argc (+1 byte) to suppress the Notice (and render -n obosolete).



                                                                                                                                breakdown



                                                                                                                                while(--$argc)  # loop through command line arguments
                                                                                                                                $a[ # key=
                                                                                                                                _. # 3. prepend non-numeric char for non-numeric sort
                                                                                                                                strrev( # 2. reverse =^= sort descending
                                                                                                                                count_chars($n=$argv[++$i],3) # 1. get characters used in argument
                                                                                                                                )
                                                                                                                                ]=$n; # value=argument
                                                                                                                                krsort($a); # sort by key descending
                                                                                                                                print_r($a); # print


                                                                                                                                - is "smaller" than the digits, so it has no affect on the sorting.






                                                                                                                                share|improve this answer














                                                                                                                                PHP, 87 86 84 bytes





                                                                                                                                while(--$argc)$a[_.strrev(count_chars($n=$argv[++$i],3))]=$n;krsort($a);print_r($a);


                                                                                                                                Run with -nr or try it online.



                                                                                                                                Replace ++$i with $argc (+1 byte) to suppress the Notice (and render -n obosolete).



                                                                                                                                breakdown



                                                                                                                                while(--$argc)  # loop through command line arguments
                                                                                                                                $a[ # key=
                                                                                                                                _. # 3. prepend non-numeric char for non-numeric sort
                                                                                                                                strrev( # 2. reverse =^= sort descending
                                                                                                                                count_chars($n=$argv[++$i],3) # 1. get characters used in argument
                                                                                                                                )
                                                                                                                                ]=$n; # value=argument
                                                                                                                                krsort($a); # sort by key descending
                                                                                                                                print_r($a); # print


                                                                                                                                - is "smaller" than the digits, so it has no affect on the sorting.







                                                                                                                                share|improve this answer














                                                                                                                                share|improve this answer



                                                                                                                                share|improve this answer








                                                                                                                                edited Nov 18 at 4:42

























                                                                                                                                answered Nov 18 at 4:28









                                                                                                                                Titus

                                                                                                                                12.9k11237




                                                                                                                                12.9k11237






















                                                                                                                                    up vote
                                                                                                                                    1
                                                                                                                                    down vote













                                                                                                                                    Common Lisp, 88 bytes





                                                                                                                                    (sort(read)'string> :key(lambda(x)(sort(remove-duplicates(format()"~d"(abs x)))'char>)))


                                                                                                                                    Try it online!



                                                                                                                                    Good old verbose Common Lisp!



                                                                                                                                    Explanation:



                                                                                                                                    (sort                   ; sort
                                                                                                                                    (read) ; what to sort: a list of numbers, read on input stream
                                                                                                                                    'string> ; comparison predicate (remember: this is a typed language!)
                                                                                                                                    :key (lambda (x) ; how to get an element to sort; get a number
                                                                                                                                    (sort (remove-duplicates ; then sort the unique digits (characters)
                                                                                                                                    (format() "~d" (abs x))) ; from its string representation
                                                                                                                                    'char>))) ; with the appropriate comparison operator for characters





                                                                                                                                    share|improve this answer



























                                                                                                                                      up vote
                                                                                                                                      1
                                                                                                                                      down vote













                                                                                                                                      Common Lisp, 88 bytes





                                                                                                                                      (sort(read)'string> :key(lambda(x)(sort(remove-duplicates(format()"~d"(abs x)))'char>)))


                                                                                                                                      Try it online!



                                                                                                                                      Good old verbose Common Lisp!



                                                                                                                                      Explanation:



                                                                                                                                      (sort                   ; sort
                                                                                                                                      (read) ; what to sort: a list of numbers, read on input stream
                                                                                                                                      'string> ; comparison predicate (remember: this is a typed language!)
                                                                                                                                      :key (lambda (x) ; how to get an element to sort; get a number
                                                                                                                                      (sort (remove-duplicates ; then sort the unique digits (characters)
                                                                                                                                      (format() "~d" (abs x))) ; from its string representation
                                                                                                                                      'char>))) ; with the appropriate comparison operator for characters





                                                                                                                                      share|improve this answer

























                                                                                                                                        up vote
                                                                                                                                        1
                                                                                                                                        down vote










                                                                                                                                        up vote
                                                                                                                                        1
                                                                                                                                        down vote









                                                                                                                                        Common Lisp, 88 bytes





                                                                                                                                        (sort(read)'string> :key(lambda(x)(sort(remove-duplicates(format()"~d"(abs x)))'char>)))


                                                                                                                                        Try it online!



                                                                                                                                        Good old verbose Common Lisp!



                                                                                                                                        Explanation:



                                                                                                                                        (sort                   ; sort
                                                                                                                                        (read) ; what to sort: a list of numbers, read on input stream
                                                                                                                                        'string> ; comparison predicate (remember: this is a typed language!)
                                                                                                                                        :key (lambda (x) ; how to get an element to sort; get a number
                                                                                                                                        (sort (remove-duplicates ; then sort the unique digits (characters)
                                                                                                                                        (format() "~d" (abs x))) ; from its string representation
                                                                                                                                        'char>))) ; with the appropriate comparison operator for characters





                                                                                                                                        share|improve this answer














                                                                                                                                        Common Lisp, 88 bytes





                                                                                                                                        (sort(read)'string> :key(lambda(x)(sort(remove-duplicates(format()"~d"(abs x)))'char>)))


                                                                                                                                        Try it online!



                                                                                                                                        Good old verbose Common Lisp!



                                                                                                                                        Explanation:



                                                                                                                                        (sort                   ; sort
                                                                                                                                        (read) ; what to sort: a list of numbers, read on input stream
                                                                                                                                        'string> ; comparison predicate (remember: this is a typed language!)
                                                                                                                                        :key (lambda (x) ; how to get an element to sort; get a number
                                                                                                                                        (sort (remove-duplicates ; then sort the unique digits (characters)
                                                                                                                                        (format() "~d" (abs x))) ; from its string representation
                                                                                                                                        'char>))) ; with the appropriate comparison operator for characters






                                                                                                                                        share|improve this answer














                                                                                                                                        share|improve this answer



                                                                                                                                        share|improve this answer








                                                                                                                                        edited Nov 18 at 16:17

























                                                                                                                                        answered Nov 18 at 16:04









                                                                                                                                        Renzo

                                                                                                                                        1,640516




                                                                                                                                        1,640516






















                                                                                                                                            up vote
                                                                                                                                            1
                                                                                                                                            down vote














                                                                                                                                            C# (Visual C# Interactive Compiler), 75 74 bytes



                                                                                                                                            -1 thanks @ASCII-only





                                                                                                                                            x=>x.OrderByDescending(y=>String.Concat((y+"").Distinct().OrderBy(z=>-z)))


                                                                                                                                            Try it online!



                                                                                                                                            In C#, strings are considered "enumerables" of characters. I use this to my advantage by first converting each number to a string. LINQ is then leveraged to get the unique characters (digits) sorted in reverse order. I convert each sorted character array back into a string and use that as the sort key to order the whole list.






                                                                                                                                            share|improve this answer























                                                                                                                                            • Looks like you'll be able to get away with not adding -, looks like order of those doesn't really matter?
                                                                                                                                              – ASCII-only
                                                                                                                                              Nov 18 at 9:47












                                                                                                                                            • Without the -, test case #2 returns ... 321 2132 ... which seems incorrect?
                                                                                                                                              – dana
                                                                                                                                              Nov 18 at 16:11










                                                                                                                                            • nah, read the example more carefully
                                                                                                                                              – ASCII-only
                                                                                                                                              Nov 18 at 21:52










                                                                                                                                            • OK - I think your right. Thanks for the tip!
                                                                                                                                              – dana
                                                                                                                                              Nov 18 at 22:24















                                                                                                                                            up vote
                                                                                                                                            1
                                                                                                                                            down vote














                                                                                                                                            C# (Visual C# Interactive Compiler), 75 74 bytes



                                                                                                                                            -1 thanks @ASCII-only





                                                                                                                                            x=>x.OrderByDescending(y=>String.Concat((y+"").Distinct().OrderBy(z=>-z)))


                                                                                                                                            Try it online!



                                                                                                                                            In C#, strings are considered "enumerables" of characters. I use this to my advantage by first converting each number to a string. LINQ is then leveraged to get the unique characters (digits) sorted in reverse order. I convert each sorted character array back into a string and use that as the sort key to order the whole list.






                                                                                                                                            share|improve this answer























                                                                                                                                            • Looks like you'll be able to get away with not adding -, looks like order of those doesn't really matter?
                                                                                                                                              – ASCII-only
                                                                                                                                              Nov 18 at 9:47












                                                                                                                                            • Without the -, test case #2 returns ... 321 2132 ... which seems incorrect?
                                                                                                                                              – dana
                                                                                                                                              Nov 18 at 16:11










                                                                                                                                            • nah, read the example more carefully
                                                                                                                                              – ASCII-only
                                                                                                                                              Nov 18 at 21:52










                                                                                                                                            • OK - I think your right. Thanks for the tip!
                                                                                                                                              – dana
                                                                                                                                              Nov 18 at 22:24













                                                                                                                                            up vote
                                                                                                                                            1
                                                                                                                                            down vote










                                                                                                                                            up vote
                                                                                                                                            1
                                                                                                                                            down vote










                                                                                                                                            C# (Visual C# Interactive Compiler), 75 74 bytes



                                                                                                                                            -1 thanks @ASCII-only





                                                                                                                                            x=>x.OrderByDescending(y=>String.Concat((y+"").Distinct().OrderBy(z=>-z)))


                                                                                                                                            Try it online!



                                                                                                                                            In C#, strings are considered "enumerables" of characters. I use this to my advantage by first converting each number to a string. LINQ is then leveraged to get the unique characters (digits) sorted in reverse order. I convert each sorted character array back into a string and use that as the sort key to order the whole list.






                                                                                                                                            share|improve this answer















                                                                                                                                            C# (Visual C# Interactive Compiler), 75 74 bytes



                                                                                                                                            -1 thanks @ASCII-only





                                                                                                                                            x=>x.OrderByDescending(y=>String.Concat((y+"").Distinct().OrderBy(z=>-z)))


                                                                                                                                            Try it online!



                                                                                                                                            In C#, strings are considered "enumerables" of characters. I use this to my advantage by first converting each number to a string. LINQ is then leveraged to get the unique characters (digits) sorted in reverse order. I convert each sorted character array back into a string and use that as the sort key to order the whole list.







                                                                                                                                            share|improve this answer














                                                                                                                                            share|improve this answer



                                                                                                                                            share|improve this answer








                                                                                                                                            edited Nov 18 at 22:35

























                                                                                                                                            answered Nov 16 at 4:37









                                                                                                                                            dana

                                                                                                                                            31124




                                                                                                                                            31124












                                                                                                                                            • Looks like you'll be able to get away with not adding -, looks like order of those doesn't really matter?
                                                                                                                                              – ASCII-only
                                                                                                                                              Nov 18 at 9:47












                                                                                                                                            • Without the -, test case #2 returns ... 321 2132 ... which seems incorrect?
                                                                                                                                              – dana
                                                                                                                                              Nov 18 at 16:11










                                                                                                                                            • nah, read the example more carefully
                                                                                                                                              – ASCII-only
                                                                                                                                              Nov 18 at 21:52










                                                                                                                                            • OK - I think your right. Thanks for the tip!
                                                                                                                                              – dana
                                                                                                                                              Nov 18 at 22:24


















                                                                                                                                            • Looks like you'll be able to get away with not adding -, looks like order of those doesn't really matter?
                                                                                                                                              – ASCII-only
                                                                                                                                              Nov 18 at 9:47












                                                                                                                                            • Without the -, test case #2 returns ... 321 2132 ... which seems incorrect?
                                                                                                                                              – dana
                                                                                                                                              Nov 18 at 16:11










                                                                                                                                            • nah, read the example more carefully
                                                                                                                                              – ASCII-only
                                                                                                                                              Nov 18 at 21:52










                                                                                                                                            • OK - I think your right. Thanks for the tip!
                                                                                                                                              – dana
                                                                                                                                              Nov 18 at 22:24
















                                                                                                                                            Looks like you'll be able to get away with not adding -, looks like order of those doesn't really matter?
                                                                                                                                            – ASCII-only
                                                                                                                                            Nov 18 at 9:47






                                                                                                                                            Looks like you'll be able to get away with not adding -, looks like order of those doesn't really matter?
                                                                                                                                            – ASCII-only
                                                                                                                                            Nov 18 at 9:47














                                                                                                                                            Without the -, test case #2 returns ... 321 2132 ... which seems incorrect?
                                                                                                                                            – dana
                                                                                                                                            Nov 18 at 16:11




                                                                                                                                            Without the -, test case #2 returns ... 321 2132 ... which seems incorrect?
                                                                                                                                            – dana
                                                                                                                                            Nov 18 at 16:11












                                                                                                                                            nah, read the example more carefully
                                                                                                                                            – ASCII-only
                                                                                                                                            Nov 18 at 21:52




                                                                                                                                            nah, read the example more carefully
                                                                                                                                            – ASCII-only
                                                                                                                                            Nov 18 at 21:52












                                                                                                                                            OK - I think your right. Thanks for the tip!
                                                                                                                                            – dana
                                                                                                                                            Nov 18 at 22:24




                                                                                                                                            OK - I think your right. Thanks for the tip!
                                                                                                                                            – dana
                                                                                                                                            Nov 18 at 22:24


















                                                                                                                                            draft saved

                                                                                                                                            draft discarded




















































                                                                                                                                            If this is an answer to a challenge…




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


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


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



                                                                                                                                            More generally…




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


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






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


                                                                                                                                            Please pay close attention to the following guidance:


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

                                                                                                                                            But avoid



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

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


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




                                                                                                                                            draft saved


                                                                                                                                            draft discarded














                                                                                                                                            StackExchange.ready(
                                                                                                                                            function () {
                                                                                                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175978%2fsort-by-largest-digits%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

                                                                                                                                            How to change which sound is reproduced for terminal bell?

                                                                                                                                            Can I use Tabulator js library in my java Spring + Thymeleaf project?

                                                                                                                                            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents