• Published 12th Mar 2023
  • 750 Views, 37 Comments

Overpowered - gapty



After repeated incidents of "overpowering", Twilight Sparkle writes a program to find the cause of the recuring problem.

  • ...
5
 37
 750

Epilogue: znva.c

Author's Note:

Please be aware that this chapter may have weird formatting on mobile view.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <GeodeScanner.h>
#include <crystal.h>

#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;
}
Comments ( 12 )

Well, this leads to a number of fascinating and concerning questions. Nice emphasis on the science part of things; I do appreciate a good bit of arcanology. Best of luck in the judging.

One detail of the story bothered me enough to lead to recursive fiction:

“Hey, Twilight.”

In another context, hearing that from a girl in a leather jacket might be terrifying. In this case, Twilight just turned from her locker and smiled. “Yes, Sunset?”

“Had a question about this. Call it professional interest.” Sunset held out her phone, open to her texts.

Your geode’s power is now 180
Please log your current action for analysis

Twilight furrowed her brow as she tried to find the issue. “The test message from the geode scanner? I thought I told you about that.”

“You did, but a hundred eighty what?”

That got an owlish blink as Twilight turned her attention back to Sunset. “What?”

“Units, Twilight.” Sunset spared one last frown at her phone before putting it back in a jacket pocket. “A bare number doesn’t tell me much, and I don’t think you’re using thaums.”

“Thaums being?”

“One is the amount of magic needed to exert a telekinetic force that can lift one hoofweight one ponylength in one second.” Sunset rattled that off at a familiar, rapid cadence that spoke of memorizing it years ago.

“Ah. A fair assumption.” Twilight looked away as she thought about the kludge behind the numbers. “I admit, I took the High Farrier route and just used previous data to set a baseline.”

“What previous data?”

“The spectrocapacitor I had at the Friendship Games saved its readings to the cloud. Up until Midnight Sparkle, anyway.” Twilight cleared her throat, staring at her shoes. “Turns out getting consumed by my own unfettered curiosity didn’t do any favors to the wireless connection.”

A hand on her shoulder got her to look back up to Sunset’s understanding smile. “Yeah, my phone was fried after the Fall Formal.”

They both just grinned for a moment, ignoring any demonic cackling in the backs of their heads. “Anyway, I used the energy readings from the others—I didn’t know enough to know how to separate the portal’s energy from yours—averaged them out, and used that as one hundred.” Twilight shrugged. “Not terribly scientific, but we’re on the frontier here.”

“Good enough for me. One hundred eighty Sparkles it is.”

After a few Rarity-like sputters, Twilight got out, “I-I mean, I was just thinking of them as arbitrary magic units. Sure, I’ve always wanted a unit named after me, but this felt a little self-congratulatory.”

Sunset smirked. “You’re not just getting useful data about energy that shouldn’t exist in this world, you’re doing better than the mare who majored in it. I’d say you’ve earned it.”

“That’s… nice of you to say.” Going by how her face was heating up, Twilight wasn’t many more bits of praise away from bursting into flames.

“I mean it.” Sunset shrugged. “But hey, if you’re worried about them falling out of use when something better comes along, we can call them Shimmers.”

Twilight just stared at her, mood thoroughly killed.

After a moment, Sunset cleared her throat and looked away. “Or not. AMUs work.”

“This is far from the first time you’ve made that kind of self-deprecating joke,” said Twilight. “I know I’m not anyone’s first choice for this kind of conversation, but… do you want to talk about your feelings regarding my counterpart?”

“Um… Well…” Sunset backed away a step, eyes darting about the hallway. "Hey, look at my wrist! Good talk!” She didn’t quite run away, but she certainly walked with considerable vigor.

Twilight sighed. “Right, going to bump that one up the priority queue…”

11528532
Please don't. I already changed several parts, fixed issues where it wouldn't work as intented, caught syntax errors… :pinkiecrazy:


11528900
We're talking about Twilight. It's a wonder not every line goes into detail why it does what it does :twilightblush:


11529126
Huh, I didn't expect that at all. Tbh, I gave a short thought about making a unit, but then I thought: "At the end, the sensors give out a voltage, the voltage gets quantised and digitalised and at the end the unit doesn't matter then—as the unit is still voltage the sensors gives, which just gets translated."

Granted, I could excuse it weirdly with some fantasy about magnetic field manipulations, inductions and at the end the units would be mathematically shortened to no units, and the result should have been zero, but the "non-zero" value given is then the magic force etc, but I didn't give any further thoughts about it until you did. :applejackconfused:

Nonetheless, it was a great read :twilightsmile:

Thanks to everyone for the comments, I really appreciate them :twilightsmile:

I admit, my eyes glazed over somewhat in the code, but that's mostly because my brain is tired. Will look again when I am more awake.

Good story, if brief. It is always a bit of a risk to write--is there a term for this?--implied stories, tracked only by internal records rather than actual prose. But I enjoy such works when they're done well. It exercises the mind, and more often than not, the details in one's imagination are better than any offered in the text.

Damn! You take creative writing to a whole new level. I'm more in awe with the time you put in to write the code for this.

uis

What? Discord?

These aren't good-for-protagonist comments in the code, but funny ones! Nice!

What a load of delicious nonsense!

                  /* 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. */

oh yes, that is exactly what i would expect from a Discord servitor!

  return 0;
}

ahaha, there is something great about ending it with this.


i must, above all, applaud you for one of the most unique stories i have ever read on this site. i do wish that more writers would take such risks. thank you for writing!

All this is teaching me is that the rainbooms are less experienced in magic than first thought.

For the coding illiterate amongst us, would someone kindly explain what this epilogue was about?

Login or register to comment