32
\$\begingroup\$

I need to stop thinking of punny names

Your task is to create as many snippets (programs that have input and output built-in), functions or full programs as possible that sorts whatever your language's version of integer arrays is in ascending order, but for each program, you're only allowed to use the characters in ASCII (or your language's code page, if it's directly specified as not ASCII) which haven't been used in the previous programs.

This is an example answer (separate programs separated by newlines):

Derp
ASdFGHJKLAAA
qwEEERtyRty

In this (fictional language), my first answer is Derp, which used up D, e, r and p. In the second program, I'm not allowed to use those character again, but I can reuse as many characters I want. Same with the third program, and so on.

Each program must take an array of integers, so something like this (see input/output examples for valid input/output styles):

[3 4 -2 5 7 196 -44 -2]

And it must output the items in the array as an array, in ascending order:

[-44 -2 -2 3 4 5 7 196]

Your score will be the total amount of submissions. If there is a tie, the lowest bytecount (least amount of bytes in your code) wins!

Rules for programs:

  • All submissions must run correctly in one language version (so Python 2 != Python 3).
  • Your submissions can be snippets, functions, or full programs. You're even allowed to mix and match them - however, you must say which is which, and provide links to working submissions.
  • Please provide online links to all solutions, if possible.
  • All submissions must take an array (or a string delimited with any character) as input, and output the array sorted (in your language's array form or as a {any character}-delimited string.
  • You are not allowed to use any characters outside of ASCII (or your language's code page).

For example, these are valid inputs/outputs:

[1 2 3 4]    (Clojure style arrays)
[1, 2, 3, 4] (Python style arrays)
1 2 3 4 5    (Space-delimited - separated by spaces)
1#2#3#4#5    ("#"-delimited - separated by "#" characters)
1\n2\n3\n4\n (newline-delimited)

Specs for input:

  • You are guaranteed that the array contains only integers. However, there may be negative numbers, and numbers may repeat indefinitely.
\$\endgroup\$
12
  • 13
    \$\begingroup\$ The more puns the better! \$\endgroup\$
    – user9206
    Mar 16, 2017 at 10:38
  • 5
    \$\begingroup\$ You realise that anyone who can be bothered to solve this in Brainfuck gets a Lenguage solution with score 128? Alternatively, a single Glypho solution could score 42. \$\endgroup\$ Mar 16, 2017 at 10:54
  • 1
    \$\begingroup\$ @Qwerp-Derp Maybe a bit tedious, but certainly doable. In fact, I expect I/O to be the most annoying part (if you don't allow reading input as a list of character codes). \$\endgroup\$ Mar 16, 2017 at 11:39
  • 1
    \$\begingroup\$ @WheatWizard I was counting only 128 available characters since the challenge specifies ASCII. \$\endgroup\$ Mar 17, 2017 at 17:24
  • 2
    \$\begingroup\$ I have 3 problems with the language restriction. (1) Restricting arbitrary classes of languages because they would be good at a challange is not fun.(2) most "Normal" programming languages like JavaScript (which already has an answer) do not meet the requirements, which is, certainly not the intent of the restriction, and once again, not fun. (3) I don't think it is really an observable requirement. "Specific function" is not very observable, I could argue through several layers of abstraction that Glypho characters do indeed have specific functions that operate on a set of hidden variables. \$\endgroup\$
    – Wheat Wizard
    Mar 17, 2017 at 18:43

16 Answers 16

15
\$\begingroup\$

Jelly, 10 programs, 65 bytes

Ṣ
¹Þ
Ụị
Œ!Ṃ
7778Ọv
Ẋ>2\S$¿
ĠFḣṪ¥@€
~Ṁ~rṀxLœ&
C»/ð+ÆNPÆfÆC_ḷ
<þḅ1‘WiþJḄ³ṫZḢ

There's some inevitable overlap with @Lynn's Jelly answer. Credits for the bogosort idea go to her.

Try it online! or verify uniqueness.

How they work

Ṣ               Main link. Argument: A (array)

Ṣ               Sort A.
¹Þ              Main link. Argument: A (array)

¹Þ              Sort A, using the identity function as the key.
Ụị              Main link. Argument: A (array)

Ụ               Grade up; yield all indices of A, sorted by their corr. values.
 ị              Index into A.
Œ!Ṃ             Main link. Argument: A (array)

Œ!              Yield all permutations of A.
  Ṃ             Minimum; yield the lexicographically smallest permutation.
7778Ọv          Main link. Argument: A (array)

7778Ọ           Unordinal; yield chr(7778) = 'Ṣ'.
     v          Evaluate with argument A.
Ẋ>2\S$¿         Main link. Argument: A (array)

      ¿         While the condition it truthy, execute the body.
 >2\S$            Condition:
     $              Combine the two links to the left into a monadic chain.
 >2\                  Perform pairwise greater-than comparison.
    S                 Sum; add the results.
                    This returns 0 iff A contains an unsorted pair of integers.
Ẋ                 Body: Shuffle A.
ĠFḣṪ¥@€         Main link. Argument: A (array)

Ġ               Group the indices of A by their sorted values.
 F              Flatten the result.
      €         Apply the link to the left to each index in the previous result, 
                calling it with the index as left argument and A as the right one.
    ¥@            Combine the two links to the left into a dyadic chain and swap
                  its arguments, so A is left one and the index i is the right one.
  ḣ               Head; take the first i elements of A.
   Ṫ              Tail; yield the last of the first i, i.e., the i-th element of A.
~Ṁ~rṀxLœ&       Main link. Argument: A (array)

~               Take the bitwise NOT of all integers in A.
 Ṁ              Take the maximum.
  ~             Take the bitwise NOT of the maximum, yielding the minimum of A.
    Ṁ           Yield the maximum of A.
   r            Range; yield [min(A), ... max(A)].
      L         Yield the length of A.
     x          Repeat each integer in the range len(A) times.
       œ&       Take the multiset-intersection of the result and A.
C»/ð+ÆNPÆfÆC_ḷ  Main link. Argument: A (array)

C               Complement; map (x -> 1-x) over A.
 »/             Reduce by dyadic maximum, yielding 1-min(A).
   ð            Begin a new, dyadic chain. Arguments: 1-min(A), A
    +           Add 1-min(A) to all elements of A, making them strictly positive.
     ÆN         For each element n of the result, yield the n-th prime number.
       P        Take the product.
        Æf      Factorize the product into prime numbers, with repetition.
          ÆC    Prime count; count the number of primes less than or equal to p,
                for each prime p in the resulting factorization.
             ḷ  Yield the left argument, 1-min(A).
            _   Subtract 1-min(A) from each prime count in the result to the left.
<þḅ1‘WiþJḄ³ṫZḢ  Main link. Argument: A (array)

<þ              Construct the less-than matrix of all pairs of elements in A.
  ḅ1            Convert each row from base 1 to integer (sum each).
    ‘           Increment. The integer at index i now counts how many elements
                of A are less than or equal to the i-th.
     W          Wrap the resulting 1D array into an array.
        J       Yield the indices of A, i.e., [1, ..., len(A)].
      iþ        Construct the index table; for each array T in the singleton array
                to the left and index j to the right, find the index of j in T.
                This yields an array of singleton arrays.
         Ḅ      Unbinary; convert each singleton from base 2 to integer, mapping
                ([x]-> x) over the array.
          ³     Yield A.
           ṫ    Tail; for each integer i in the result of `Ḅ`, create a copy of A
                without its first i-1 elements.
            Z   Zip/transpose. The first column becomes the first row.
             Ḣ  Head; yield the first row.
\$\endgroup\$
15
\$\begingroup\$

Jelly, 8 programs

Ṣ                   Built-in sort.
¹Þ                  Sort-by the identity function.
Ụị                  Sort indices by values, then index into list.
Œ!Ṃ                 Smallest permutation.
7778Ọv              Eval Unicode 7778 (Ṣ).
ẊI>@-.S$$¿          Bogosort.
<;0œṡ0⁸ṁjµ/         Insertion sort.
AṀ‘¶+Ç©ṬT_©®³ċЀ®x' A terrifying hack.

The last program is really annoying…

AṀ‘¶+Ç©               Add ® = abs(max(L)) + 1 to the entire list.
                      Now it’s offset to be entirely positive.
       Ṭ              Create a binary array with 1s at these indices.
        T             Find the indices of 1s in this array.
                      The result is sorted, but offset wrong, and lacks duplicates.
         _©®          Subtract the offset, saving this list to ®.
                      Now restore the duplicates:
            ³ċЀ      Count occurences in the original list.
                ®x'   Repeat the elements of ® that many times.

If I can remove the œṡ from <;0œṡ0⁸ṁjµ/, there’s also this weird one: ²SNr²ZFœ&. Help is appreciated.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Roots → polynomial, polynomial → roots is genius! \$\endgroup\$
    – Luis Mendo
    Mar 16, 2017 at 17:07
  • 1
    \$\begingroup\$ It appears the output order is reversed. Luckily U is free \$\endgroup\$
    – Luis Mendo
    Mar 16, 2017 at 17:07
  • \$\begingroup\$ Ugh, negative integers… I’ll see what I can do about those \$\endgroup\$
    – Lynn
    Mar 16, 2017 at 20:07
  • \$\begingroup\$ I think we need a bit more, but I don't know how we could improve it. \$\endgroup\$ Mar 17, 2017 at 11:43
  • \$\begingroup\$ @ETHproductions Fixed, now. \$\endgroup\$
    – Lynn
    Mar 17, 2017 at 17:19
14
\$\begingroup\$

05AB1E, score = 6

05AB1E uses CP-1252 encoding.

Thanks to Kevin Cruijssen for program 4.
Thanks to Riley for inspiration to program 6.

Program 1

{               # sort          

Try it online!

Program 2

`[Ž.^]¯

`               # flatten input list to stack
 [Ž  ]          # loop until stack is empty
   .^           # add top of stack to global list in sorted order
      ¯         # push global list

Try it online!

Program 3

WrZŠŠŸvy†

Wr              # get minimum value in input list and reverse stack
  ZŠ            # get maximum value in input list and swap move it to bottom of stack
    Š           # move input down 2 levels of the stack
     Ÿ          # create a range from max to min
      v         # for each y in range
       y†       # move any occurrence of it in the input list to the front

Try it online!

Program 4

ϧ

œ               # get a list of all permutations of input
 ß              # pop the smallest

Try it online!

Program 5

êDgFDNè¹sUXQOFXs}}\)

ê                      # sort with duplicates removed
 Dg                    # duplicate and get length
   F                   # for N in [0 ... len-1] do
    DNè                # duplicate and get the Nth element in the unique list
       ¹s              # push input and move the Nth element to top of stack
         UX            # save it in X
           Q           # compare each element in the list against the Nth unique element
            O          # sum
             FXs}      # that many times, push X and swap it down 1 level on stack
                 }     # end outer loop
                  \    # remove the left over list of unique items
                   )   # wrap stack in a list

Try it online!

Program 6

©€Ý逤þ((®€Ý逤(þ(Rì

©                        # store a copy of input in register
 €Ý                      # map range[0 ... n] over list
   é                     # sort by length
    €¤                   # map get_last_element over list
      þ((                # keep only non-negative numbers
                         # now we have all positive numbers sorted
         ®€Ý逤(þ(       # do the same thing again on input 
                         # except now we only keep negative numbers
                  R      # reverse sorting for negative numbers
                   ì     # prepend the sorted negative numbers to the positive ones

Try it online!

\$\endgroup\$
13
  • \$\begingroup\$ œß Can be used for an additional score. Try it here. \$\endgroup\$ Mar 16, 2017 at 11:05
  • \$\begingroup\$ @KevinCruijssen: Thanks! I was just looking at a œ solution, but I didn't even know about ß :) \$\endgroup\$
    – Emigna
    Mar 16, 2017 at 11:07
  • \$\begingroup\$ I will be completely honest, I got it from here. ;) \$\endgroup\$ Mar 16, 2017 at 11:08
  • 1
    \$\begingroup\$ @Riley Unless I'm doing something wrong, it gives an incorrect output \$\endgroup\$ Mar 16, 2017 at 13:31
  • 1
    \$\begingroup\$ Is there a way to get the tail and pop? €Ý逤 would work if ¤ popped the value instead if just getting it. \$\endgroup\$
    – Riley
    Mar 16, 2017 at 13:34
11
\$\begingroup\$

Brachylog, score =  4  5

Program 1 - Shuffle sort

ṣ.↔:1≥₎∧|↰

We shuffle and check that the reverse of the list is non-increasing. If not we retry recursively.

Program 2 - Permutation sort

p≤₁

Output the first permutation which is non-decreasing.

Program 3 - Built-in

o

Order.

Program 4 - Built-in

≜ᵒ

Order by labeling. Since the integers in the list are already fixed, this does the same as o.

Program 5 - Min printing

g~kKt~lg~kK{⌋M&~cṪ↺Th[M]hẉTb↺c}ⁱ⁾

Here's an explanation for this monstrosity of Nature:

g~kK                                K = [Input list, a variable]
    t~lg~kK                         That variable is the length of the Input list
           {                  }ⁱ⁾   Iterate length-of-the-Input times on the Input:
            ⌋M                        M is the min of the input
              &~cṪ                    Ṫ is a triplet of lists which concatenate to the input
                 Ṫ↺Th[M]              T is Ṫ cyclically permuted once ccw; [M] is
                                        the first element of T
                        hẉ            Write M followed by a new line
                          Tb↺c        Remove the first element of T (i.e. [M]), cyclically
                                        pemute T once ccw and concatenate; this is
                                        the input for the next iteration
\$\endgroup\$
4
  • 3
    \$\begingroup\$ Crossed out 4 is still regular 4 :( \$\endgroup\$ Mar 16, 2017 at 17:50
  • 2
    \$\begingroup\$ @NoOneIsHere I cheated and extended the line to circumvent that! \$\endgroup\$
    – Fatalize
    Mar 16, 2017 at 19:40
  • \$\begingroup\$ Tail recursion + bogosort. Looks like a recipe f- RecursionError: maximum call stack size exceeded \$\endgroup\$ Mar 17, 2017 at 2:50
  • \$\begingroup\$ @Challenger5 Tail recursion is implemented well enough in Prolog so that this should not happen. \$\endgroup\$
    – Fatalize
    Mar 17, 2017 at 7:22
7
\$\begingroup\$

JavaScript, score 1 2

Doubled the score thanks to @ETHproductions who reminded me of string escapes

Snippet 1 (21 bytes, characters \ ,-.=>289`Facehilnorstux)

Function`return this.sort\x28\x28t,h\x29=>t-h\x29`.call

Snippet 2 (9117 bytes, characters (+)[!])

[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+(!![]+[])[+[]]+(+(+!+[]+[+[]]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(+![]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(+![]+[![]]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]](!+[]+!+[]+[+!+[]])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]+!+[]]+(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+(![]+[])[+!+[]]+[[]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]([[]])+[]+(+(+!+[]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(+![]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(+![]+[![]]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]](!+[]+!+[]+[+[]])+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]()[+!+[]+[+!+[]]]+([]+[])[([![]]+[][[]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]]()[!+[]+!+[]]+(![]+[])[+!+[]]+(+((+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]+[+[]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+!+[]]])+[])[!+[]+!+[]]+(+(+!+[]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(+![]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(+![]+[![]]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]](!+[]+!+[]+[+[]])+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]

You can test both versions in your browser's console. The first version is just a function, the second version is a snippet that needs the parentheses and argument added.

Examples

< {function snippet here}([1, -44, 65, -105, 12])
> [-105, -44, 1, 12, 65]

How?

The first snippet calls the sort method on the array you pass it. By default, the sort method sorts lexicographical, which is bad for integers (especially multi-digit negative numbers). As such, we have to pass it a callback in the form of an arrow function that takes two elements and subtracts the latter from the former. Depending on the resulting value, the two elements are rearranged: if it is smaller than 0, a will appear before b, if it is larger than 0, a will appear after b, and if it is 0, both elements will end up next to each other.

The second snippet is nothing more than an encoded version of the first snippet and it takes advantage of the fact that in JavaScript, object.function() equals object["function"](). It also uses empty arrays, ! operators and number casting to generate all kinds of strings, in which the needed characters for the function name can be found. Then the brackets are used once more to get the character at a certain index in the string, and all those characters are concatenated, resulting in the following JavaScript code:

[]["fill"]["constructor"]("return this.sort((a,b)=>a-b)")["call"]

[]["fill"] equals [].fill, whose ["constructor"] is the Function object. We then call that with a string (which is to be evaluated when the function is called), which is the first function, but notice that the argument has been replaced by this. To set the value of this to the argument, we need to call a function on this function, namely ["call"]. In conventional JavaScript, you would write this as:

function _() {
    return this.sort((a,b)=>a-b);
}
_.call(argument);
\$\endgroup\$
2
  • \$\begingroup\$ I bet it's possible to get a solution without parentheses, using backticks instead. Function`return a=>a.sort\x28\x28a,b\x29=>a-b\x29` for example, but without using the chars you've already used \$\endgroup\$ Mar 17, 2017 at 0:24
  • \$\begingroup\$ Not that it matters, but you could probably save a significant amount of bytes in the second snippet by introducing ' and doing e.g. '(' instead of whatever JSF generates that char. (also, use f and t as the vars instead of a and b, b literally costs about 3000 chars) \$\endgroup\$ Mar 17, 2017 at 20:35
7
\$\begingroup\$

V, score 3, 4

This was a really fun challenge! Thankfully, vim has a builtin "sort" function, otherwise this would basically be impossible. Unfortunately, it since V/vim are string based it needs an argument to sort by numeric values. So I'm calling

  • Sort by numerical value n,

  • Sort by hexadecimal value x, and

  • Sort by floating point value f

Little side-note: When I write something like <esc> or <C-r>, this is a actually a single-byte. It represents unprintable characters, and since V unfortunately relies heavily on unprintable characters, this method makes everything easier. The TIO links have the -v flag, which makes the V interpreter read these as if they were the characters they represent.

Program 1, 2 bytes

ún

Try it online!

This calls the V specific sort function.

Program 2, 10 bytes

Qsor x
vi

This just calls 'sort' directly. The only interesting thing about this is that we do it from ex mode, which is a weird mode that emulates the text editor 'ex', V's great-great-grandfather. vi is a shortcut for visual, the command used to leave ex mode. This requires a trailing newline.

Try it online!

Program 3, 14 bytes

OSOR X<esc>V~DJ:<C-r>"

Try it online!

Alright, here is where the explanations start to get a little weird. If we can build up the text sor x, we can delete it and insert it into the current command with <C-r><register-name>. So we'll enter it uppercase.

O                       " Open a newline above the current line, and enter insert mode
 SOR X                  " From insert mode, enter 'SOR X'
      <esc>             " Leave insert mode
           V            " Select this whole line
            ~           " And toggle the case of every selected character ('u' would also work here)
             D          " Delete this line (into register '"')
              J         " Get rid of a newline
               :        " Enter command-line mode
                <C-r>"  " Insert register '"'
                        " Implicitly hit enter, running the 'sor x' command
                        " Implicitly print the buffer

Program 4, 19 bytes

YPC<C-v>58fbe a<C-c>g?_dd@1

Try it online!

And here is where the explanations start to get very weird. Similar to last time, we'll build the command up in normal mode so that we can use different keys.

YP                          " Create a copy of this line up one line. This is mostly so that we have a line to work with without messing with the numbers.
  C                         " Delete this line and enter insert mode
   <C-v>58                  " Insert ASCII '58' (which is ':')
          fbe a             " Insert 'fbe a'
               <C-c>        " Pretty much equivalent to <esc>
                    g?_     " ROT13 this line. Now the line is ':sor n'
                       dd   " Delete this whole line
                         @1 " And run it as if typed
\$\endgroup\$
6
\$\begingroup\$

CJam, score 4

Program 1: Built-in

$

Program 2: Eval'ed Built-in

36c~

36 is the ASCII value of $.

Program 3: Permutation Sort

e!0=

e!     e# Find unique permutations of the input
  0=   e# Take the first one, which happens to be in sorted order

Program 4: Min Values

[{__)\;\{_@_@<{\}&;}*^{1m<}{)\}?}h;]

Explanation of this unearthly monstrosity:

[             e# Begin working in an array
{             e# Do this block while the TOS is truthy (doesn't pop)
 __           e#  Duplicate TOS twice (the array)
 )\;          e#  Take the last element of the array
 \            e#  Swap top two elements, bringing the other array copy to the top
 {            e#  Reduce the array using this block
  _@_@<{\}&;  e#   The minimum of two values (e was already used, so can't use e<)
 }*           e#  (result is the minimum value from the array)
 ^            e#  Bitwise XOR of last element with minimum element;
              e#   if the numbers are the same, result is 0, otherwise non-zero
 {            e#  If non-zero (i.e. last element wasn't the minimum element)
  1m<         e#   Rotate the array 1 to the left
 }{           e#  Else
  )\          e#   Remove the last element and bring the array back to TOS
 }?           e#  (end if)
}h            e# (end do-while)
;             e# Remove the empty array left behind
]             e# End the array
\$\endgroup\$
3
  • \$\begingroup\$ Not sure how helpful it is but you can use (+ instead of 1m< if you want. \$\endgroup\$ Mar 16, 2017 at 15:31
  • \$\begingroup\$ @MartinEnder I'm already using < in that snippet so it's probably better to stick with 1m< \$\endgroup\$ Mar 16, 2017 at 15:45
  • \$\begingroup\$ Though I'm not sure I'll be able to do anymore anyway without using blocks... \$\endgroup\$ Mar 16, 2017 at 15:47
5
\$\begingroup\$

Japt, score = 4

Program 1

n

Try it online!

Program 2

ñ

Try it online!

Program 3

s)$.sort((a,b)=>a-b

Try it online!

Program 4

Ov85d +110d

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Nice one. I think you can save the U in the third program by doing s)$.sort(..., not sure if that's useful though. \$\endgroup\$ Mar 16, 2017 at 13:58
  • \$\begingroup\$ @ETHproductions Thanks. I'm not really sure if I can do much more anyway; can't eval any more Japt or JS because O and $ have been used. I'm open for suggestions if you can think of any other ways of sorting! :) \$\endgroup\$
    – Tom
    Mar 16, 2017 at 14:04
4
\$\begingroup\$

Octave, 2 points

It's hard to compete with esolangs, but here goes:

I'm impressed if someone beats this. unique can be used to sort values, but it will strip out the duplicates. In order to insert the duplicates you would need parentheses, and they are heavily used in the bubble-sort. You'd also need @, which is used too.

Number 1:

This one is quite simple: Create an anonymous function, assigned to the variable ans.

@sort

Call it this way: ans([-5, 3, 0, -2, 100]). It doesn't work on tio, but it works on octave-online.


Number 2:

This is simply an implementation of bubble sort, without using the characters @sort. We can't make this a function, because of o, and we can't use input because of the t. We're therefore stuck with eval.

eval(['a=inpu',116,'("");']);i=1;k=0;
while~k,k=1;i=1;while i<numel(a),if a(i)>a(i+1),a([i+1,i]) = a([i,i+1]);k=0;
end,i++;end,end,a

eval(['a=inpu',116,'("");']); evaluates to: a=input("");, that we can use to enter our input vector. The rest is bubble-sorting without using for or mod. Note that this must be saved in a script and called from the GUI/CLI. You can't copy-paste it, because of input("") (it will use the rest of the code as input, thus fail miserably).

\$\endgroup\$
4
\$\begingroup\$

Haskell (lambdabot), 3 functions

sort


vv v|vvv:vvvv<-v=vv vvvv|v==v=v
vvvv==:vvv|vvvv==vv vvvv=vvv:vvvv|v:vv<-vvvv,vvv<v=vvv:v:vv|v:vv<-vvvv=v:vv==:vvv
vv=:vvvv|v:vvv<-vvvv=vv==:v=:vvv
vv=:v=vv
v vvv=vv vvv=:vvv


fix(ap(min).ap((++).flip(map)[1].(.(0*)).(+).minimum).(.ap(\\)(flip(map)[1].(.(0*)).(+).minimum)))

I'm using the lambdabot environment to avoid lots of import statements. Even sort needs import Data.List. lambdabot imports a bunch of modules by default. Besides the missing imports, it's standard Haskell code according to our rules.

Try it online!.

Function 1

sort

The library function from Data.List. Nothing much to say here.

Function 2

vv v|vvv:vvvv<-v=vv vvvv|v==v=v
vvvv==:vvv|vvvv==vv vvvv=vvv:vvvv|v:vv<-vvvv,vvv<v=vvv:v:vv|v:vv<-vvvv=v:vv==:vvv
vv=:vvvv|v:vvv<-vvvv=vv==:v=:vvv
vv=:v=vv
v vvv=vv vvv=:vvv

Function v implements an insert-sort.

I use pattern guards to avoid () for parameters. Compare vv v|vvv:vvvv<-v=... to vv(vvv:vvvv)=....

The first line, function vv is a helper function to create the empty list. With it I don't have to use [] to write literal empty lists. More readable:

mkEmpty list | hd:tl <- list = mkEmpty tl | otherwise = list

(==:) is insert, which inserts an element into a sorted list, so that the resulting list is still sorted. More readable:

list `insert` el
  | list == []           = el:list
  | hd:tl <- list, el<hd = el:hd:tl
  | hd:tl <- list        = hd : tl `insert` el

(=:) is reduce. More readable:

acc `reduce` list
  | hd:tl <- list = (acc `insert` hd) `reduce` tl
acc `reduce` list = acc

And finally v which reduces the input list staring with []:

sort list = [] `reduce` list

Function 3

fix(ap(min).ap((++).flip(map)[1].(.(0*)).(+).minimum).(.ap(\\)(flip(map)[1].(.(0*)).(+).minimum)))

sort from Function 1 makes most of the list-walking functions (fold, scan, until) unavailable. Recursion needs = which is used in Function 2. The only option left is using the fixpoint combinator fix. I've started with

fix (\f x -> min x ([minimum x]++f(x\\[minimum x])))

which is a selection-sort. Turning it to point-free (I cannot use lambdas \f x ->..., because of the - which is used by the pattern gurads in Function 2) gives:

fix (ap min . ap ((++) . return . minimum) . (. ap (\\) (return . minimum)))

Making singleton lists out of a value with return is forbidden (same for pure), so I have to build my own function: \x -> map (\y -> x+0*y) [1] or point-free flip map[1].(.(0*)).(+). Replacing return yields

fix(ap(min).ap((++).flip(map)[1].(.(0*)).(+).minimum).(.ap(\\)(flip(map)[1].(.(0*)).(+).minimum)))
\$\endgroup\$
2
\$\begingroup\$

MATL, 3 programs

Program 1

S

This just uses the builtin function, with implicit input and display.

Try it at MATL online.

Program 2

`GGnZrd0<a}3M

This keeps generating random permutations of the inputs until all consecutive differences of the result are non-negative (this is bogosort, as noted by @c.z.). Running time is non-deterministic and its average increases very fast with input size (namely, 𝒪(n!) for a size-n array with all entries different).

Try it at MATL Online.

Program 3

t:"tt_X>_=&)]&h

This is a loop that computes the minimum of the array, removes all elements equal to that value, and proceds with the rest. This is done as many times as the input size. If not all entries in the input are different, some of the iterations will be useless (but harmless), because the array will have already been emptied.

Try it at MATL online.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Nice lateral thinking! \$\endgroup\$ Mar 16, 2017 at 16:48
  • \$\begingroup\$ Is that bogo-sort? \$\endgroup\$
    – c..
    Mar 16, 2017 at 21:28
  • \$\begingroup\$ @c.z. googles bogo-sort Indeed! TIL \$\endgroup\$
    – Luis Mendo
    Mar 16, 2017 at 23:01
1
\$\begingroup\$

Pip, 4 programs

Program 1 - builtin

Snippet; assumes list in x.

SNx

(SN for Sort Numeric)

Program 2 - filter permutations

Snippet; assumes list in y. Very slow for inputs longer than about 7 items.

Y$<=_FIPMyPOy

       PMy     List of permutations of y
     FI        Filter on this lambda function:
 $<=_           Fold on less-than-or-equal
                (gives 1 if the permutation is sorted ascending, 0 otherwise)
Y              Yank that result back into y
               Filter returned a list of (one or more) permutations, so we need to
          POy  Pop the first one

Program 3 - eval

Snippet; assumes list in z.

V J C[83 78 122]

    C[83 78 122]  Apply chr to each number; yields ["S" "N" "z"]
  J               Join that list into a string
V                 Eval

Program 4 - MergeSort

Anonymous function; call with list as argument (like ({...} [1 2]) or f:{...} (f [1 2]).

{b:#a>o?(fa@(,#a/2))lc:#a>o?(fa@(#a/2,()))aa:lWb{Wb@0>c@0|b@0Qc@0{aAE:c@0c@>:o}t:bb:cc:t}aALc}

Ungolfed:

{
 ; If more than one element in a, b gets result of recursion with first half
 ; else b gets l (empty list)
 b: #a>o ? (f a@(,#a/2)) l
 ; If more than one element in a, c gets result of recursion with second half
 ; else c gets a
 c: #a>o ? (f a@(#a/2,())) a
 ; Now we merge b and c
 ; We'll put the results in a, which must be initialized to l (empty list)
 a:l
 ; Loop while b is nonempty
 W b {
  ; Loop while 0th element of c exists and is less than or equal to 0th element
  ; of b (note: Q is string equality)
  W b@0>c@0 | b@0Qc@0 {
   ; Append 0th element of c to a
   a AE: c@0
   ; Slice c from 1st element on and assign that back to c (removing 0th)
   c @>: o
  }
  ; Swap b and c
  t:b
  b:c
  c:t
 }
 ; When b is empty, we only need append the rest of c to a and return
 aALc
}
\$\endgroup\$
1
\$\begingroup\$

PowerShell, 2

|sort

Try it online!

This is a snippet that runs in (e.g.) PowerShell's equivalent of a REPL. The TIO link shows usage. The sort is an alias for the Sort-Object cmdlet.


PARAM($A)[ARRAY]::SORT($A);$A

Try it online!

PowerShell commands are case-insensitive, so we can use sort for one and SORT for the other. This takes an input array, sorts it in-place, and then outputs it.

\$\endgroup\$
1
\$\begingroup\$

Ruby, 2 programs

First - the straightforward:

->t{t.sort}

Second - the tricky part:

def w(g)
    eval ""<<103<<46<<115<<111<<114<<116
end
\$\endgroup\$
0
\$\begingroup\$

J

Program one: 3 bytes

/:~

as in /:~ 3,1,2,1 outputs 1 1 2 3

Try it online!

NOTE in J, negative numbers are preceded by _ not - so you can try 4,_10,56,_333 etc.

Program two: 5 bytes

|.\:~
\$\endgroup\$
3
  • \$\begingroup\$ I fixed up your answer so that the code is displayed properly. Nice answer! Also, the Try it online thing links to a webpage on TIO, to link a page in an answer you can do this: [displayed text](link). \$\endgroup\$
    – clismique
    Mar 17, 2017 at 8:59
  • \$\begingroup\$ Thanks! Just starting out so getting the hang of it slowly! Think it looks better now. Your help much appreciated. Richard \$\endgroup\$ Mar 17, 2017 at 9:11
  • \$\begingroup\$ The programs you write may not share any characters; as-is, : and ~ occur in both of them. \$\endgroup\$
    – Lynn
    Mar 17, 2017 at 19:34
0
\$\begingroup\$

PHP 7, 2 programs

Both programs can be golfed more.

Program 1, 254 bytes, characters ! "$&+.01:;=>?[]adeginoprtv

$a=$argv;0 .$a[1+1]?$i=$n=$d=0:print$a[1]and die;g:$r=0 .$a[++$i+1];$i=!$r?1:$i;$n=!$r?$n+1:$n;$v=$i+1;$d=$v>$d?$v:$d;$n>$d?print$a[$d]and die:0;$e=$d>$n&&$a[$i]>$a[$v];$t=$a[$i];$a[$i]=$e?$a[$v]:$a[$i];$a[$v]=$e?$t:$a[$v];$n==$d?print"$a[$i] ":0;goto g;

Bubble sort. Uses goto to create a loop as built-in loops require ().

Program 2, 155 bytes, characters #%'(),-67ACEFINORTUYZ^_{|}~

IF(CREATE_FUNCTION('','NEFTIEZIENAECCERCTZIENA~N~UEEFECTZIENAUERTEF~CFACTY~YRZIENAUE'^')))6()~(7)7~6-677|~(7)7%~#|~6)77|~(7)7|~77-)^))(-|~^~~~(7)7|~')()){}

IF(...){} avoids usage of ;. The main code is encoded with XOR, because $ has been already used in the previous program. The code:

global$argv;unset($argv[0]);sort($argv);echo join(' ',$argv);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.