//------------------------------// // Epilogue: znva.c // Story: Overpowered // by gapty //------------------------------// #include #include #include #include #include #include #define ELEMENTS_SIZE 7 // Which number will it be? 0? 182? Not bigger than 999 for sure! int generate_random_number() {     return rand() % 1000; } // Oh, Fisher-Yates algorithm, how much I love you void shuffle_array(int* array, int size) {     for (int i = size - 1; i > 0; i--) {         int j = rand() % (i + 1);         int temp = array[i];         array[i] = array[j];         array[j] = temp;     } } // I like bubbles, and I will use the Bubble Sort algorithm even if it’s slow! Why else did I buy four CPUs that even NASA would envy me for? void sort_array(int* array, int size) {     for (int i = 0; i < size - 1; i++) {         for (int j = 0; j < size - i - 1; j++) {             if (array[j] > array[j + 1]) {                 int temp = array[j];                 array[j] = array[j + 1];                 array[j + 1] = temp;             }         }     } } // Time to see which lucky number they will get! int are_they_lucky() {     // For more fun, even the array size is randomized!     int array_size = rand() % 16000;     array_size = array_size * 2;     // Here comes the random numbers!     int* array = (int*)malloc(array_size * sizeof(int));     for (int i = 0; i < array_size; i++) {         array[i] = generate_random_number();     }     // And now a loop until the lucky number is left!     while (array_size > 1) {         // Shuffle the array for luck!         shuffle_array(array, array_size);         // Sort the first half of the array. A little order necessary for BUBBLES!         int half_size = array_size / 2;         sort_array(array, half_size);         // Only the first half survives! Which number will it be?         array_size = half_size;     }     // The lucky number has been generated! Time to see which it was!     int result = array[0];     free(array);     return result; } int main() {     srand(time(NULL));  // Time for chaos!     int crystal_power = 0; // Go, my little crystal!     int power_level[ELEMENTS_SIZE] = {0};     int previous_power_level[ELEMENTS_SIZE] = {0};          // Repeat until Crystal is powered up! Or if I lose…     while (crystal_power < 500) {         // Which action shall it be?         for (int i = 0; i < ELEMENTS_SIZE; i++) {             power_level[i] = read_power_level(i);             // Oh no, their Harmony doesn’t decrease! Disconnect the crystal! :o             if (previous_power_level[i] >= power_level[i]) {                 disconnect_crystal(i);                 previous_power_level[i] = power_level[i];             }             // Our little girl is acting out of Harmony! Time for a little fun! >:)             else {                 previous_power_level[i] = power_level[i];                 // Let’s spin the wheel of Fortune!                 switch (are_they_lucky()) {                 case 13:                     printf("Looks like you have an extra misfortune!\n");                     printf("More feeding of your interconnected falling power level!\n");                 connect_crystal_all();                     break;                 case 100:                     printf("I hate this number! Random chance!\n");                     connect_crystal(rand() % (ELEMENTS_SIZE + 1));                     break;                 case 178:                     printf("Time for more chaos! For no reason!\n");                     for (int j; j < rand() % 9164; j++) {                         int irrelevant_number = rand() % 13649;                     }                     connect_crystal(i);                     break;                 case 222:                     printf("Timeout! -ZzZ-\n");                     sleep(rand() % 500);                     break;                 case 777:                     printf("There it goes. The Rainbooms gained the lottery win :(\n");                     printf("It was a fun time serving you, Discord,\n");                     printf("but it was inevitable. Let Chaos reign in another way!\n");                     printf("Program is shutting down.\n");                     disconnect_crystal_all();                     return 0;                     break;                 case 1972:                     /* Let us praise the year this wonderful, chaotic, unreadable and undeterminable programming language was made! Gone are the developments of readable and understandable code! Chaos, C, it’s all connected! In honor, let us do a calculation that is possible to do in C. */                     int C = rand() % 98;                     int H = rand() % 83;                     C = ++C<<1+--H%2<<2*C--<<3%3-H++%1-C*H-H<<2%2;                     connect_crystal(i);                     break;                 default:                     // No luck for you, Rainbooms! Feed my crystal with your Disharmony!                     connect_crystal(i);                 }             }         }         crystal_power = measure_crystal_power();     }     // I won >:)     printf("The crystal is filled with Disharmony!\n");     printf("The Chaos has been awakened!\n");     printf("The reign of Discord won’t be stoppable!\n");     printf("It was an honor serving you. Have fun with your new power!\n");     return 0; }