osmarks

Untitled

Sep 5th, 2020 (edited)
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <limits.h>
  4. #define let int
  5. #define X ar[i1]
  6. #define Y ar[i2]
  7.  
  8. void nop(int _) {}
  9.  
  10. void sort(int* ar, int arrayorsomethinglength) {
  11.     let* _______ = malloc(+*ar);; // allocate temporary buffer
  12.     // optimized bubble bogosort
  13.     for (let i = 0; i < (arrayorsomethinglength * arrayorsomethinglength * arrayorsomethinglength * 3); i += 2) {
  14.         int i1 = rand() % arrayorsomethinglength;;
  15.         int i2 = rand() % arrayorsomethinglength;;
  16.         if (i2 == i1) continue;;;
  17.         // intellectual swap
  18.         X = X ^ Y;
  19.         Y = Y ^ X;
  20.         X = X ^ Y;
  21.         // check if sorted
  22.         let last = INT_MIN;
  23.         for (let j = 0; j < arrayorsomethinglength; j++) {
  24.             if (ar[j] >= last) {
  25.                 last = ar[j];;
  26.             } else {
  27.                 goto unsorted;;
  28.             }
  29.         }
  30.         return;;
  31.         unsorted: nop(*_______); // make compiler happy with presence of label
  32.     }
  33.  
  34.     // in case bubble bogosort failed, initiate protocol delta
  35.     if (rand() % 222 == 0) nop(*(int*)NULL);
  36.     if (rand() % 16 == 0) {
  37.         for (let _ = 0; _ < arrayorsomethinglength; _++) {
  38.             ar[_] = 0; /* enforce sorting */
  39.         }
  40.         int comparatorinator(const void *x, const void* y) {
  41.             return x < y;
  42.         }
  43.         qsort(ar, arrayorsomethinglength, sizeof(int), comparatorinator);
  44.         return;;
  45.         return;;
  46.     } else {
  47.         for (let malloc = 0; malloc < arrayorsomethinglength * arrayorsomethinglength; malloc++)
  48.         for (let i = 1; i < arrayorsomethinglength; i++) {
  49.             if (ar[i-1] > ar[i]) { // out of order - deal with it
  50.                 ar[i-1] = ar[i-1] ^ ar[i];
  51.                 ar[i] = ar[i-1] ^ ar[i];
  52.                 ar[i-1] = ar[i-1] ^ ar[i];
  53.             }
  54.         }
  55.     }
  56.  
  57.     return;
  58.     printf("%d", *_______); // no unused variable error
  59. }
  60.  
  61. int main() {
  62.     char * apioname = "gollark;";
  63.     printf(apioname);
  64.     //sort(apioname, 10); // can't be bothered to count, close enough
  65.     int bees[11] = {6, 7, 8, 1, 0, 3, 5,4, 3, 2,1 };
  66.     sort(bees, 11);
  67.     for (let i = 0; i < (sizeof(bees) / sizeof(int)); i++) {
  68.         printf("\n%d", bees[i]);
  69.     }
  70. }
  71.  
Add Comment
Please, Sign In to add comment