SHARE
TWEET

Untitled

a guest Jun 24th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ϧ
  2.      
  3. E[ß,Ž
  4.      
  5. Œ!Ṃ
  6.      
  7. ṂrṀf
  8.      
  9. ṂrṀf  Main link. Argument: A (list/comma-separated string)
  10.  
  11. Ṃ     Compute the minimum of A.
  12.   Ṁ   Compute the maximum of A.
  13.  r    Yield the inclusive range from the minimum to the maximum.
  14.    f  Filter the range by presence in A.
  15.      
  16. lambda l:[l.pop(l.index(min(l)))for _ in 1*l]
  17.      
  18. p.'(s>)
  19.      
  20. p.       Unifies the output with a permutation of the input
  21.   '(  )  True if what's inside the parentheses cannot be proven, else backtrack and
  22.          try with another permutation of the input.
  23.     s    Take an ordered subset from the output
  24.      >   True if the first element is bigger than the second (hence not sorted)
  25.          We don't need to check that the subset is 2 elements long because > will be false
  26.          for inputs that are not 2 elements long anyway
  27.      
  28. a=>a.map(_=>m=Math.min(...a.filter(e=>e>m)),m=-1/0)
  29.      
  30. f u=filter(`elem`u)[(minBound::Int)..]
  31.      
  32. 2 address  16-bit       bubblesort16_v2:
  33.  3          machine      ;; inputs: pointer in ds:si,  size in in cx
  34.  4          code         ;; requires: DF=0  (cld)
  35.  5          bytes        ;; clobbers: al, cx=0
  36.  6                      
  37.  7 00000000 49               dec     cx          ; cx = max valid index.  (Inner loop stops 1 before cx, because it loads i and i+1).
  38.  8                       .outer:                 ; do{
  39.  9 00000001 51               push    cx          ;   cx = inner loop counter = i=max_unsorted_idx
  40. 10                       .inner:                 ;   do{
  41. 11 00000002 AC               lodsb               ;     al = *p++
  42. 12 00000003 3804             cmp     [si],al     ;     compare with *p (new one)
  43. 13 00000005 7D04             jge     .noswap
  44. 14 00000007 C144FF08         rol     word [si-1], 8    ; swap
  45. 15                       .noswap:
  46. 16 0000000B E2F5             loop    .inner      ;   } while(i < size);
  47. 17 0000000D 59               pop     cx          ;  cx = outer loop counter
  48. 18 0000000E 29CE             sub     si,cx       ;  reset pointer to start of array
  49. 19 00000010 E2EF             loop    .outer      ; } while(--size);
  50. 20 00000012 C3               ret
  51.  
  52. 22 00000013  size = 0x13 = 19 bytes.
  53.      
  54. 2 Address               ;; hybrib Bubble Selection sort
  55.  3        machine         bubblyselectionsort_int32:   ;; working, 19 bytes.  Same size for int32 or int8
  56.  4        code               ;; input: pointer in rsi, count in rcx
  57.  5        bytes              ;; returns: eax = max
  58.  6                      
  59.  7                           ;dec  ecx           ; we avoid this by doing edi=esi *before* lodsb, so we do redundant compares
  60.  8                                               ; This lets us (re)enter the inner loop even for 1 element remaining.
  61.  9                       .outer:
  62. 10                           ; rsi pointing at the element that will receive min([rsi]..[rsi+rcx])
  63. 11 00000000 56               push   rsi
  64. 12 00000001 5F               pop    rdi
  65. 13                           ;mov    edi, esi     ; rdi = min-search pointer
  66. 14 00000002 AD               lodsd
  67. 16 00000003 51               push   rcx          ; rcx = inner counter
  68. 17                       .inner:                   ; do {
  69. 18                           ; rdi points at next element to check
  70. 19                           ; eax = candidate min
  71. 20 00000004 AF               scasd                 ; cmp eax, [rdi++]
  72. 21 00000005 7E03             jle  .notmin
  73. 22 00000007 8747FC           xchg   [rdi-4], eax   ; exchange with new min.
  74. 23                         .notmin:
  75. 24 0000000A E2F8             loop  .inner          ; } while(--inner);
  76. 26                           ; swap min-position with sorted position
  77. 27                           ; eax = min.  If it's not [rsi-4], then [rsi-4] was exchanged into the array somewhere
  78. 28 0000000C 8946FC           mov    [rsi-4], eax
  79. 29 0000000F 59               pop   rcx           ; rcx = outer loop counter = unsorted elements left
  80. 30 00000010 E2EE             loop  .outer        ; } while(--unsorted);
  81. 32 00000012 C3               ret
  82.  
  83. 34 00000013 13           .size: db $ - bubblyselectionsort_int32
  84.            0x13 = 19 bytes long
  85.      
  86. i,j;a(int*l,int n){for(i=0;i=i?:--n;j>l[n]?l[i]=l[n],l[n]=j:0)j=l[--i];}
  87.      
  88. Y@t!d0>AY)
  89.      
  90. % Implicitly grab input array
  91. Y@      % Compute all permutations (each permutation as a row)
  92. t       % Duplicate this matrix
  93. !d      % Transpose and take the differences between the values
  94. 0>A     % Find the rows where all differences are > 0
  95. Y)      % Return only the row where this is true
  96.         % Implicitly display the result
  97.      
  98. ->a{r=[];r<<a.delete(a.min)while[]!=a;r}
  99.      
  100. def f(a):import time,threading;[threading.Thread(None,lambda b=b,c=min(a):print(time.sleep(b-c)or b)).start()for b in a]
  101.      
  102. Address    Code        Basic                     Source
  103.  
  104. 0x00400000  0x3c011001  lui $1,4097           5    main:   la      $s0, list       # List address
  105. 0x00400004  0x34300000  ori $16,$1,0              
  106. 0x00400008  0x2411000a  addiu $17,$0,10       6            li      $s1, 10         # List length
  107. 0x0040000c  0x24080000  addiu $8,$0,0         8    loop:   li      $t0, 0          # swapped
  108. 0x00400010  0x24090001  addiu $9,$0,1         9            li      $t1, 1          # for loop "i"
  109. 0x00400014  0x1131000b  beq $9,$17,11         11   for:    beq     $t1, $s1, fend  # break if i==length
  110. 0x00400018  0x00095080  sll $10,$9,2          13           sll     $t2, $t1, 2     # Temp index, multiply by 4
  111. 0x0040001c  0x01505020  add $10,$10,$16       14           add     $t2, $t2, $s0   # Combined address
  112. 0x00400020  0x8d4b0000  lw $11,0($10)         15           lw      $t3, 0($t2)     # list[i]
  113. 0x00400024  0x8d4cfffc  lw $12,-4($10)        16           lw      $t4, -4($t2)    # list[i-1]
  114. 0x00400028  0x21290001  addi $9,$9,1          18           addi    $t1, $t1, 1     # i++
  115. 0x0040002c  0x016c082a  slt $1,$11,$12        20           ble     $t4, $t3, for   # if list[i-1] > list[i]
  116. 0x00400030  0x1020fff8  beq $1,$0,-8              
  117. 0x00400034  0xad4bfffc  sw $11,-4($10)        21           sw      $t3, -4($t2)    # swap and store
  118. 0x00400038  0xad4c0000  sw $12,0($10)         22           sw      $t4, 0($t2)    
  119. 0x0040003c  0x24080001  addiu $8,$0,1         23           li      $t0, 1          # swapped=true
  120. 0x00400040  0x08100005  j 0x00400014          24           j       for
  121. 0x00400044  0x20010001  addi $1,$0,1          26   fend:   subi    $s1, $s1, 1     # length--
  122. 0x00400048  0x02218822  sub $17,$17,$1            
  123. 0x0040004c  0x1500ffef  bne $8,$0,-17         27           bnez    $t0, loop       # Repeat if swapped==true
  124. 0x00400050  0x2402000a  addiu $2,$0,10        29           li      $v0, 10        
  125. 0x00400054  0x0000000c  syscall               30           syscall
  126.      
  127. {b=$0;a[b]}m<b{m=b}n>b{n=b}END{for(i=n;i<=m;i++)if(i in a)print i}
  128.      
  129. `t4#X<2#)tn
  130.      
  131. `        % Do...while loop
  132.   t      %   Duplicate. Implicitly take input in the first iteration
  133.   4#X<   %   Compute index of mininum of the array
  134.   2#)    %   Push the minimum, and then the array with remaining entries
  135.   tn     %   Duplicate and push number of elements, to be used as loop condition
  136.          % Implicitly end do...while loop
  137.          % Implicitly display stack contents
  138.      
  139. f!s>VTtT.p
  140.      
  141. ,;l@╨m
  142.      
  143. ,;l@╨m
  144. ,;l@    push len(input), input
  145.     ╨m  minimum permutation
  146.      
  147. ,1WX╚;;pX@dXZ`i@-0<`MπYWX
  148.      
  149. ,1WX╚;;pX@dXZ`i@-0<`MπYWX
  150. ,                          get input
  151.  1W                    WX  do-while:
  152.    X                         discard
  153.     ╚                        shuffle
  154.      ;;                      dupe twice
  155.        pX@dX                 remove first element of first dupe and last element of second dupe
  156.             Z                zip
  157.              `i@-0<`MπY      test if all differences are positive (if any are not, the list is not sorted), negate (1 if not sorted else 0)
  158.      
  159. vTbtX<-QI$(f8M+q
  160.      
  161. v                  % push an empty array
  162.  T                 % push 1
  163.   b                % bubble the input array up to the top of the stack
  164.    t               % duplicate it
  165.     X<             % find the minimum
  166.       -            % subtract min from input array
  167.        Q           % and increment to adjust for 1-based indexing
  168.         I$(        % resulting array used as indices of empty array
  169.                    % (the [] way up at the top) that are assigned 1 (from T)
  170.            f       % find the nonzero indices
  171.             8M     % magically retrieve the 4th previous function input :/
  172.                      (aka, the min input array value)
  173.               +    % add it to the indices
  174.                q   % and decrement
  175.      
  176. x->colon(extrema(x)...)∩x
  177.      
  178. o<-i
  179. for(j in 1:length(i)){
  180. x<-(i-min(i))==0
  181. o[j]<-i[x]
  182. i<-i[!x]
  183. }
  184. o
  185.      
  186. o<-i                      # Defines output as o
  187.  for(j in 1:length(i)){   # Initializes loop for length of input
  188.   x<-(i-min(i))==0        # Generates logical vector by finding the value 0
  189.                           # of input less the minimum of input.
  190.    o[j]<-i[x]             # Puts the smallest value at position j
  191.     i<-i[!x]              # Removes the smallest value from input
  192.       }                   # Ends loop
  193.        o                  # Returns sorted list
  194.      
  195. -d+
  196. $*n
  197. d+
  198. $*11
  199. +`(1+) (n+)
  200. $2 $1
  201. +`b(n+) (1n+)|(1+)(1+) 3b
  202. $2$3 $1$3$4
  203. 1(1*)
  204. $.1
  205. n+
  206. -$.&
  207.      
  208. ->a{a.permutation.min}
  209.      
  210. #(if(apply < %)%(recur(shuffle %)))
  211.      
  212. #(reduce(fn[r i](let[[a b](split-with(partial > i)r)](concat a[i]b)))[]%)
  213.      
  214. ->l{l.map{l-l-=[l.min]}}
  215.      
  216. ->l{l.map{l-l-=[l.min]}}[[2,4,3,1]]
  217. => [[1], [2], [3], [4]]
  218.      
  219. void a(int[]a){for(int b=a.length-1,d=0,c=0,e;d<b*b;c=++d%b)if(a[c]>a[c+1]){e=a[c];a[c++]=a[c];a[c]=e;}}
  220.      
  221. ->a{[*a.min..a.max]&a}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top