这是字节的挑战


32

我需要别再想笨拙的名字了

您的任务是创建尽可能多的代码片段(内置输入和输出的程序),函数或完整程序,以对您所用语言的整数数组版本进行升序排序,但是对于每个程序,只允许使用使用以前的程序中未使用过的ASCII字符(如果直接将其指定为非ASCII,则使用您的语言的代码页)。

这是一个示例答案(用换行符分隔的单独程序):

Derp
ASdFGHJKLAAA
qwEEERtyRty

在这种(虚构的语言),我的第一个答案是Derp,它使用了Derp。在第二个程序中,不允许再次使用这些字符,但是我可以重用任意多个字符。与第三个程序相同,依此类推。

每个程序必须采用整数数组,因此类似以下内容(有关有效的输入/输出样式,请参见输入/输出示例):

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

并且它必须以升序将数组中的项目输出为数组:

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

您的分数将是提交的总数。如果有平局,则最低字节数(代码中字节数最少)获胜!

程序规则:

  • 所有提交必须以一种语言版本(so Python 2 != Python 3)正确运行。
  • 您的提交可以是摘要,功能或完整程序。您甚至可以混合和匹配它们-但是,您必须说出哪个是哪个,并提供工作提交的链接。
  • 如果可能,请提供所有解决方案的在线链接。
  • 所有提交都必须以数组(或用任何字符分隔的字符串)作为输入,并输出排序后的数组(以您语言的数组形式或- {any character}分隔的字符串)。
  • 您不得使用ASCII(或您的语言的代码页)以外的任何字符。

例如,这些是有效的输入/输出:

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

输入规格:

  • 您可以确保该数组仅包含整数。但是,可能会有负数,并且数字可能会无限期重复。

13
双关语越多越好!

5
您意识到,任何可以在Brainfuck中解决此问题的人都可以得到128分的Lenguage解决方案?另外,单Glypho解决方案能得分42
马丁安德

1
@ Qwerp-Derp可能有点乏味,但确实可行。实际上,我希望I / O是最烦人的部分(如果您不允许将输入作为字符代码列表进行读取)。
马丁·恩德

1
@WheatWizard因为挑战指定ASCII,所以我只计算了128个可用字符。
Martin Ender

2
我在语言限制方面有3个问题。(1)限制任意种类的语言,因为它们会带来挑战,这很不好玩。(2)大多数“普通”编程语言(例如JavaScript)(已经有答案)不能满足要求,这当然不是意图的限制,再一次,不好玩。(3)我认为这并不是一个真正可以观察到的要求。“特定功能”不是很明显,我可以通过几层抽象来证明Glypho字符确实具有对一组隐藏变量进行操作的特定功能。
小麦巫师

Answers:


15

果冻,10个程序,65字节

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

@Lynn的Jelly答案有一些不可避免的重叠。她对bogosort的想法功不可没。

在线尝试!验证唯一性

他们如何工作

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

15

果冻,8个程序

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

最后一个程序真烦人...

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.

如果我可以删除œṡ<;0œṡ0⁸ṁjµ/,这里还有这个奇怪的一个:²SNr²ZFœ&。感谢帮助。


1
Roots → polynomial, polynomial → roots天才!
Luis Mendo

1
看来输出顺序是相反的。幸运的U是免费
Luis Mendo

唉,负整数......我去看看我能做些什么关于那些
林恩

我认为我们还需要更多,但是我不知道如何改善它。
马修·罗

@ETHproductions已修复,现在。
林恩

14

05AB1E,得分= 6

05AB1E使用CP-1252编码。

感谢Kevin Cruijssen的程序4。
感谢Riley对程序6的启发。

程序1

{               # sort          

在线尝试!

程序2

`[Ž.^]¯

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

在线尝试!

程序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

在线尝试!

程序4

ϧ

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

在线尝试!

程序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

在线尝试!

计划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

在线尝试!


œß可以用于其他分数。在这里尝试。
Kevin Cruijssen

@KevinCruijssen:谢谢!我只是在寻找œ解决方案,但我什至不知道ß:)
Emigna

我将完全诚实,我是从这里得到的。;)
Kevin Cruijssen

1
@Riley除非我做错什么,否则它会给出错误的输出
Kevin Cruijssen

1
有没有办法让尾巴弹出呢?€Ý逤如果¤弹出该值,则可以工作,而只是获得它即可。
莱利

11

Brachylog,得分=  4  5

计划1-随机排序

ṣ.↔:1≥₎∧|↰

我们重新排序,并检查列表的反数是否增加。如果没有,我们将递归重试。

程序2-排列排序

p≤₁

输出不递减的第一个排列。

程序3-内置

Ø

订购。

程序4-内置

≜ᵒ

通过标签订购。由于列表中的整数已经固定,因此与o

计划5-最小印刷

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

这是对这种自然怪兽的解释:

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

3
划掉

2
@NoOneIsHere在此欺骗并扩展了行号以规避!
致命

尾递归+ bogosort。看起来像是食谱f-RecursionError: maximum call stack size exceeded
硕果累累

@ Challenger5尾部递归在Prolog中实现得很好,因此不应发生这种情况。
致命

7

JavaScript,得分1 2

@ETHproductions使得分翻倍,他使我想起了字符串转义

片段1(21个字节,字符\ ,-.=>289`Facehilnorstux

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

片段2(9117字节,字符(+)[!]

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

您可以在浏览器的控制台中测试这两个版本。第一个版本只是一个函数,第二个版本是需要添加括号和参数的代码段。

例子

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

怎么样?

第一个代码段在您传递的数组上调用sort方法。默认情况下,sort方法对字典顺序进行排序,这对整数(尤其是多位数的负数)不利。因此,我们必须以箭头函数的形式向其传递一个回调,该回调函数接受两个元素,并从前一个元素中减去后者。根据结果​​值,两个元素将重新排列:如果小于0,a将出现在前面b;如果大于0,a则将出现在后面b;如果为0,则两个元素将彼此相邻。

第二个片段只是第一个片段的编码版本,它利用了JavaScript中object.function()equals 的事实object["function"]()。它还使用空数组,!运算符和数字转换来生成各种字符串,可以在其中找到函数名称所需的字符。然后,再次使用方括号将字符获取到字符串中某个索引处,然后将所有这些字符连接起来,得到以下JavaScript代码:

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

[]["fill"] 等于 [].fill,其["constructor"]Function对象。然后,我们使用一个字符串(将在调用该函数时对其进行评估)来调用它,这是第一个函数,但请注意,该参数已被替换this。要将this参数的值设置为参数,我们需要在此函数上调用函数,即["call"]。在传统的JavaScript中,您可以这样编写:

function _() {
    return this.sort((a,b)=>a-b);
}
_.call(argument);

我敢打赌,使用反引号可以得到不带括号的解决方案。Function`return a=>a.sort\x28\x28a,b\x29=>a-b\x29` 例如,但不使用您已经使用过的字符
ETHproductions

没关系,但是您可以通过引入'并执行例如'('而不是JSF生成该char的方法,在第二个代码段中节省大量字节。(同样,使用fand t作为var代替aand bb字面价值约为3000个字符)
ETHproductions

7

V,成绩3,4

这是一个非常有趣的挑战!幸运的是,vim具有内置的“排序”功能,否则,这基本上是不可能的。不幸的是,由于V / vim是基于字符串的,因此它需要一个参数以按数值排序。所以我打电话

  • 按数值排序 n

  • 按十六进制值排序 x,以及

  • 按浮点值排序 f

小提示:当我写类似<esc>或的内容时<C-r>,实际上是一个单字节。它表示无法打印的字符,并且由于V严重依赖于无法打印的字符,因此此方法使一切变得容易。TIO链接具有-v标志,这使V解释器将它们视为它们所代表的字符来读取。

程序1,2字节

ún

在线尝试!

这称为V特定排序功能。

程序2,10个字节

Qsor x
vi

这只是直接称为“排序”。唯一有趣的是,我们是从ex模式执行的,这是一种奇怪的模式,它模仿文本编辑器“ ex”(V的曾曾祖父)。vi是的快捷方式visual,该命令用于退出ex模式。这需要尾随换行符。

在线尝试!

程式3,14位元组

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

在线尝试!

好了,这里的解释开始变得有些奇怪了。如果我们可以构建文本sor x,则可以将其删除并将其插入到当前命令中<C-r><register-name>。因此,我们将其大写。

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

程序4,19字节

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

在线尝试!

这就是解释开始变得奇怪的地方。与上次类似,我们将在普通模式下构建命令,以便我们可以使用不同的键。

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

6

CJam,得分4

程序1:内置

$

程序2:评估内置

36c~

36是的ASCII值$

程序3:排列排序

e!0=

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

计划4:最低价值

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

关于这种怪异怪物的解释:

[             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

不知道它是如何有帮助的是,但你可以使用(+,而不是1m<如果你想。
马丁·恩德

@MartinEnder我已经<在该代码段中使用了,所以最好坚持一下1m<
Business Cat

尽管我不确定我是否仍可以在不使用块的情况下做任何事情……
Business Cat

5

Japt,得分= 4

程序1

n

在线尝试!

程序2

ñ

在线尝试!

程序3

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

在线尝试!

程序4

Ov85d +110d

在线尝试!


1
好东西。我认为您可以通过执行来将U保存在第三个程序中s)$.sort(...,但是不确定是否有用。
ETHproductions

@ETHproductions谢谢。我不确定我是否还能做更多的事情。无法再评估Japt或JS,因为O$已被使用。如果您能想到其他任何排序方式,欢迎您提出建议!:)
Tom

4

八度,2点

与esolangs竞争很难,但是这里有:

如果有人打败我,我会印象深刻。unique可以用于对值进行排序,但是它将去除重复项。为了插入重复项,您需要括号,并且它们在冒泡排序中被大量使用。您还需要@使用。

1号:

这很简单:创建一个匿名函数,并将其分配给变量ans

@sort

这样称呼:ans([-5, 3, 0, -2, 100])。它不适用于tio,但适用于octave-online


2号:

这只是气泡排序的一种实现,而没有使用character @sort。由于,我们不能使它成为函数,并且由于o,我们不能使用inputt。因此,我们坚持使用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,'("");']);计算为:a=input("");,我们可以用来输入输入向量。其余的不使用for或进行气泡排序mod。请注意,必须将其保存在脚本中并从GUI / CLI调用。您不能复制粘贴它,因为input("")(它会将其余代码用作输入,因此惨遭失败)。


4

Haskell(lambdabot),3个功能

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

我正在使用lambdabot环境来避免很多import语句。甚至sort需要import Data.List。lambdabot默认情况下会导入一堆模块。除了失踪imports根据我们的规则,,标准的Haskell代码。

在线尝试!

功能1

sort

的库函数Data.List。在这里没什么好说的。

功能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

函数v实现插入排序。

我使用模式防护来避免()使用参数。比较vv v|vvv:vvvv<-v=...vv(vvv:vvvv)=...

第一行,函数vv是创建空列表的辅助函数。有了它,我不必用[]书面的空列表。更具可读性:

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

(==:)是insert,它将元素插入已排序列表中,以便仍对结果列表进行排序。更具可读性:

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

(=:)减少。更具可读性:

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

最后v,这减少了输入列表的起始位置[]

sort list = [] `reduce` list

功能3

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

sort从功能1使得大多数的列表行走功能(foldscanuntil)不可用。=函数2中使用了递归需求。剩下的唯一选择是使用fixpoint组合器fix。我开始

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

这是一种选择。将其设置为无点(我不能使用lambdas \f x ->...,因为-函数2中的模式gurads 使用了lambdas )会得出:

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

return禁止使用值使单例列表(与相同pure),因此我必须构建自己的函数:\x -> map (\y -> x+0*y) [1]或自由点flip map[1].(.(0*)).(+)。更换return收益

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

2

MATL,3个程序

程序1

S

这仅使用内置函数以及隐式输入和显示。

MATL在线试用

程序2

`GGnZrd0<a}3M

这将继续生成输入的随机排列,直到结果的所有连续差都为非负数为止(这是bogosort,如@cz所示)。运行时间是不确定的,它的平均值随输入大小的增加而迅速增加(即,对于大小为n的数组,所有条目都不相同,𝒪(n!)。

MATL Online上尝试一下。

程序3

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

这是一个循环,它计算数组的最小值,删除等于该值的所有元素,然后处理其余的元素。完成此操作的次数与输入大小相同。如果输入中的所有条目不是​​全部都不同,则某些迭代将是无用的(但无害),因为该数组已被清空。

在线MATL尝试一下。


1
不错的横向思考!
格雷格·马丁

那是波哥大排序吗?
ç..

@cz Googles bogo-sort确实如此!TIL
Luis Mendo'Mar

1

,4个程序

程序1内置

片段;承担中的清单x

SNx

SN用于数字排序)

程序2过滤器排列

片段;承担中的清单y。输入超过7个项目的速度非常慢。

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

程序3评估

片段;承担中的清单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

程序4 -MergeSort

匿名函数;以list作为参数调用(如({...} [1 2])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}

取消高尔夫:

{
 ; 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
}

1

PowerShell的,2

|sort

在线尝试!

这是一个片段,可以在(例如)PowerShell的REPL等价版本中运行。TIO链接显示用法。该sort是对的别名Sort-Objectcmdlet的。


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

在线尝试!

PowerShell命令不区分大小写,因此我们可以将它们sort用于SORT另一个。这需要一个输入数组,对其进行原位排序,然后输出。


1

Ruby,2个程序

首先-简单明了:

->t{t.sort}

第二-棘手的部分:

def w(g)
    eval ""<<103<<46<<115<<111<<114<<116
end

0

Ĵ

程序一:3字节

/:~

/:~ 3,1,2,1输出1 1 2 3

在线尝试!

注意在J中,负数以_开头-可以尝试4,_10,56,_333等。

程序二:5字节

|.\:~

我已修正您的答案,以便正确显示代码。好答案!此外,Try it online东西连接到TIO网页,在网页在回答中,你可以做此链接:[displayed text](link)
clismique

谢谢!刚开始,所以慢慢掌握它!认为现在看起来更好。非常感谢您的帮助。理查德
理查德·多诺万

您编写的程序不能共享任何字符;照原样出现,:并且都~在两者中发生。
林恩

0

PHP 7,2个程序

这两个程序都可以打更多。

程序1,254个字节,字符 ! "$&+.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;

气泡排序。用于goto根据内置循环的要求创建循环()

程序2,155个字节,字符 #%'(),-67ACEFINORTUYZ^_{|}~

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

IF(...){}避免使用;。主代码使用XOR编码,因为$先前的程序已经使用过。代码:

global$argv;unset($argv[0]);sort($argv);echo join(' ',$argv);
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.