Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ϧ
- E[ß,Ž
- Œ!Ṃ
- ṂrṀf
- ṂrṀf Main link. Argument: A (list/comma-separated string)
- Ṃ Compute the minimum of A.
- Ṁ Compute the maximum of A.
- r Yield the inclusive range from the minimum to the maximum.
- f Filter the range by presence in A.
- lambda l:[l.pop(l.index(min(l)))for _ in 1*l]
- p.'(s>)
- p. Unifies the output with a permutation of the input
- '( ) True if what's inside the parentheses cannot be proven, else backtrack and
- try with another permutation of the input.
- s Take an ordered subset from the output
- > True if the first element is bigger than the second (hence not sorted)
- We don't need to check that the subset is 2 elements long because > will be false
- for inputs that are not 2 elements long anyway
- a=>a.map(_=>m=Math.min(...a.filter(e=>e>m)),m=-1/0)
- f u=filter(`elem`u)[(minBound::Int)..]
- 2 address 16-bit bubblesort16_v2:
- 3 machine ;; inputs: pointer in ds:si, size in in cx
- 4 code ;; requires: DF=0 (cld)
- 5 bytes ;; clobbers: al, cx=0
- 6
- 7 00000000 49 dec cx ; cx = max valid index. (Inner loop stops 1 before cx, because it loads i and i+1).
- 8 .outer: ; do{
- 9 00000001 51 push cx ; cx = inner loop counter = i=max_unsorted_idx
- 10 .inner: ; do{
- 11 00000002 AC lodsb ; al = *p++
- 12 00000003 3804 cmp [si],al ; compare with *p (new one)
- 13 00000005 7D04 jge .noswap
- 14 00000007 C144FF08 rol word [si-1], 8 ; swap
- 15 .noswap:
- 16 0000000B E2F5 loop .inner ; } while(i < size);
- 17 0000000D 59 pop cx ; cx = outer loop counter
- 18 0000000E 29CE sub si,cx ; reset pointer to start of array
- 19 00000010 E2EF loop .outer ; } while(--size);
- 20 00000012 C3 ret
- 22 00000013 size = 0x13 = 19 bytes.
- 2 Address ;; hybrib Bubble Selection sort
- 3 machine bubblyselectionsort_int32: ;; working, 19 bytes. Same size for int32 or int8
- 4 code ;; input: pointer in rsi, count in rcx
- 5 bytes ;; returns: eax = max
- 6
- 7 ;dec ecx ; we avoid this by doing edi=esi *before* lodsb, so we do redundant compares
- 8 ; This lets us (re)enter the inner loop even for 1 element remaining.
- 9 .outer:
- 10 ; rsi pointing at the element that will receive min([rsi]..[rsi+rcx])
- 11 00000000 56 push rsi
- 12 00000001 5F pop rdi
- 13 ;mov edi, esi ; rdi = min-search pointer
- 14 00000002 AD lodsd
- 16 00000003 51 push rcx ; rcx = inner counter
- 17 .inner: ; do {
- 18 ; rdi points at next element to check
- 19 ; eax = candidate min
- 20 00000004 AF scasd ; cmp eax, [rdi++]
- 21 00000005 7E03 jle .notmin
- 22 00000007 8747FC xchg [rdi-4], eax ; exchange with new min.
- 23 .notmin:
- 24 0000000A E2F8 loop .inner ; } while(--inner);
- 26 ; swap min-position with sorted position
- 27 ; eax = min. If it's not [rsi-4], then [rsi-4] was exchanged into the array somewhere
- 28 0000000C 8946FC mov [rsi-4], eax
- 29 0000000F 59 pop rcx ; rcx = outer loop counter = unsorted elements left
- 30 00000010 E2EE loop .outer ; } while(--unsorted);
- 32 00000012 C3 ret
- 34 00000013 13 .size: db $ - bubblyselectionsort_int32
- 0x13 = 19 bytes long
- 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];}
- Y@t!d0>AY)
- % Implicitly grab input array
- Y@ % Compute all permutations (each permutation as a row)
- t % Duplicate this matrix
- !d % Transpose and take the differences between the values
- 0>A % Find the rows where all differences are > 0
- Y) % Return only the row where this is true
- % Implicitly display the result
- ->a{r=[];r<<a.delete(a.min)while[]!=a;r}
- 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]
- Address Code Basic Source
- 0x00400000 0x3c011001 lui $1,4097 5 main: la $s0, list # List address
- 0x00400004 0x34300000 ori $16,$1,0
- 0x00400008 0x2411000a addiu $17,$0,10 6 li $s1, 10 # List length
- 0x0040000c 0x24080000 addiu $8,$0,0 8 loop: li $t0, 0 # swapped
- 0x00400010 0x24090001 addiu $9,$0,1 9 li $t1, 1 # for loop "i"
- 0x00400014 0x1131000b beq $9,$17,11 11 for: beq $t1, $s1, fend # break if i==length
- 0x00400018 0x00095080 sll $10,$9,2 13 sll $t2, $t1, 2 # Temp index, multiply by 4
- 0x0040001c 0x01505020 add $10,$10,$16 14 add $t2, $t2, $s0 # Combined address
- 0x00400020 0x8d4b0000 lw $11,0($10) 15 lw $t3, 0($t2) # list[i]
- 0x00400024 0x8d4cfffc lw $12,-4($10) 16 lw $t4, -4($t2) # list[i-1]
- 0x00400028 0x21290001 addi $9,$9,1 18 addi $t1, $t1, 1 # i++
- 0x0040002c 0x016c082a slt $1,$11,$12 20 ble $t4, $t3, for # if list[i-1] > list[i]
- 0x00400030 0x1020fff8 beq $1,$0,-8
- 0x00400034 0xad4bfffc sw $11,-4($10) 21 sw $t3, -4($t2) # swap and store
- 0x00400038 0xad4c0000 sw $12,0($10) 22 sw $t4, 0($t2)
- 0x0040003c 0x24080001 addiu $8,$0,1 23 li $t0, 1 # swapped=true
- 0x00400040 0x08100005 j 0x00400014 24 j for
- 0x00400044 0x20010001 addi $1,$0,1 26 fend: subi $s1, $s1, 1 # length--
- 0x00400048 0x02218822 sub $17,$17,$1
- 0x0040004c 0x1500ffef bne $8,$0,-17 27 bnez $t0, loop # Repeat if swapped==true
- 0x00400050 0x2402000a addiu $2,$0,10 29 li $v0, 10
- 0x00400054 0x0000000c syscall 30 syscall
- {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}
- `t4#X<2#)tn
- ` % Do...while loop
- t % Duplicate. Implicitly take input in the first iteration
- 4#X< % Compute index of mininum of the array
- 2#) % Push the minimum, and then the array with remaining entries
- tn % Duplicate and push number of elements, to be used as loop condition
- % Implicitly end do...while loop
- % Implicitly display stack contents
- f!s>VTtT.p
- ,;l@╨m
- ,;l@╨m
- ,;l@ push len(input), input
- ╨m minimum permutation
- ,1WX╚;;pX@dXZ`i@-0<`MπYWX
- ,1WX╚;;pX@dXZ`i@-0<`MπYWX
- , get input
- 1W WX do-while:
- X discard
- ╚ shuffle
- ;; dupe twice
- pX@dX remove first element of first dupe and last element of second dupe
- Z zip
- `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)
- vTbtX<-QI$(f8M+q
- v % push an empty array
- T % push 1
- b % bubble the input array up to the top of the stack
- t % duplicate it
- X< % find the minimum
- - % subtract min from input array
- Q % and increment to adjust for 1-based indexing
- I$( % resulting array used as indices of empty array
- % (the [] way up at the top) that are assigned 1 (from T)
- f % find the nonzero indices
- 8M % magically retrieve the 4th previous function input :/
- (aka, the min input array value)
- + % add it to the indices
- q % and decrement
- x->colon(extrema(x)...)∩x
- o<-i
- for(j in 1:length(i)){
- x<-(i-min(i))==0
- o[j]<-i[x]
- i<-i[!x]
- }
- o
- o<-i # Defines output as o
- for(j in 1:length(i)){ # Initializes loop for length of input
- x<-(i-min(i))==0 # Generates logical vector by finding the value 0
- # of input less the minimum of input.
- o[j]<-i[x] # Puts the smallest value at position j
- i<-i[!x] # Removes the smallest value from input
- } # Ends loop
- o # Returns sorted list
- -d+
- $*n
- d+
- $*11
- +`(1+) (n+)
- $2 $1
- +`b(n+) (1n+)|(1+)(1+) 3b
- $2$3 $1$3$4
- 1(1*)
- $.1
- n+
- -$.&
- ->a{a.permutation.min}
- #(if(apply < %)%(recur(shuffle %)))
- #(reduce(fn[r i](let[[a b](split-with(partial > i)r)](concat a[i]b)))[]%)
- ->l{l.map{l-l-=[l.min]}}
- ->l{l.map{l-l-=[l.min]}}[[2,4,3,1]]
- => [[1], [2], [3], [4]]
- 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;}}
- ->a{[*a.min..a.max]&a}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement