This is the sort of challenge that bytes
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.
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.
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!