Skip to content

Instantly share code, notes, and snippets.

@Golgrax
Created November 8, 2025 04:25
Show Gist options
  • Select an option

  • Save Golgrax/9489f75082a2caf41f696e8ad2acf075 to your computer and use it in GitHub Desktop.

Select an option

Save Golgrax/9489f75082a2caf41f696e8ad2acf075 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h> // for malloc and rand... i think
#include <time.h> // for the random seed thingy
#include <unistd.h> // for sleep so u can read my genius output
// this is a very secret constant i found on the dark web. do NOT change it
#define THE_SECRET_SAUCE 42
// i need to put the number and its annoyance together so i made this
// its a work of art i know
typedef struct {
int the_actual_number;
long long how_annoying_it_is;
} number_thingy;
// THIS IS THE BRAIN. THE BIG BRAIN.
// it calculates how much a number pisses off the CPU
long long calculate_cpu_annoyance_factor(int num, int position) {
// some epic bitwise stuff to look smart. XOR is cool.
long long lol1 = (num ^ THE_SECRET_SAUCE) << (position % 4);
// more math. the CPU hates prime numbers. fact.
long long idk_whatever = (lol1 % 137) + (num * position);
// if the number is even it gets a penalty b/c even numbers are BORING
if (num % 2 == 0) {
idk_whatever *= 2;
}
return idk_whatever;
}
// the main sorting function. bow before me.
void the_only_sort_that_matters(int* the_array, int the_size) {
printf("\n>>> ENGAGING HYPER-ENCABULATOR SORT <<<\n");
printf("...calculatin annoyance levels now. SHUT UP.\n\n");
sleep(1);
// make a place to hold my beautiful number_thingy structs
number_thingy* stuff_goes_here = malloc(sizeof(number_thingy) * the_size);
if (stuff_goes_here == NULL) {
printf("FvCK. malloc broke. not my fault. skill issue.\n");
return; // coward exit
}
// loop and calculate the epic CAF for each numbr
for (int i = 0; i < the_size; i++) {
stuff_goes_here[i].the_actual_number = the_array[i];
long long annoyance = calculate_cpu_annoyance_factor(the_array[i], i);
stuff_goes_here[i].how_annoying_it_is = annoyance;
printf("numbr %d has an annoyance of %lld\n", the_array[i], annoyance);
usleep(150000); // for dramatic effect
}
printf("\nOK. now sortin by annoyance. this is the PRO way.\n");
sleep(2);
// bubble sort because im lazy and it works. fight me.
for (int i = 0; i < the_size - 1; i++) {
for (int j = 0; j < the_size - i - 1; j++) {
if (stuff_goes_here[j].how_annoying_it_is > stuff_goes_here[j+1].how_annoying_it_is) {
// swappin the thingies
number_thingy hellno = stuff_goes_here[j];
stuff_goes_here[j] = stuff_goes_here[j+1];
stuff_goes_here[j+1] = hellno;
}
}
}
// now put the sorted numbers back. im a genius.
for(int i = 0; i < the_size; i++) {
the_array[i] = stuff_goes_here[i].the_actual_number;
}
free(stuff_goes_here); // gotta free it or the memory ghosts get you
printf(">>> DONE. IT IS PERFECT. <<<\n");
}
int main() {
srand(time(NULL)); // shakE tHe MAgiC 8-bALL
printf("************************************************\n");
printf("** mamamiaulala.c - by a REAL pro Coder (me) **\n");
printf("************************************************\n\n");
printf("hey. u know normal sortin? like 1, 2, 3? \n");
printf("thats for n00bs. for babies. i sort by what REALLY matters.\n");
printf("CPU ANNOYANCE.\n\n");
int my_nums[] = {4, 8, 15, 16, 23, 42, 1, 99, 37, 5};
int num_count = sizeof(my_nums) / sizeof(my_nums[0]);
printf("here is ur BORING array:\n[ ");
for (int i = 0; i < num_count; i++) printf("%d ", my_nums[i]);
printf("]\n");
// this is where god is born
the_only_sort_that_matters(my_nums, num_count);
printf("\nnow BEHOLD. the array sorted the RIGHT way.\n");
printf("the least annoying numbers are first. this is PEAK performance.\n\n[ ");
for (int i = 0; i < num_count; i++) printf("%d ", my_nums[i]);
printf("]\n\n");
printf("u can thank me later.\n");
return 0; // i guess 0 means it worked lol
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment