ID:95968
 
Keywords: programming
void magic(char* c) {
        size_t len = strlen(c);
        char temp;
        short toggle = 0;

        for(size_t it = 0; it < len; it++) {
                for(size_t i = toggle; i < len - 1; i+=2) {
                        temp = c[i]; c[i] = c[i+1]; c[i+1] = temp;
                }

                toggle = (toggle+1)%2;
        }
}


An algorithm that may be useful to constructors of conveyor-belt-driven robot-sorters.
Idk C++(or possibily C), but that looks like it does next to nothing XD?
What it does is it seems to shift all of the characters in said string over to the left by one.
It changes invisible pink unicorns to purple.
SuperAntx wrote:
It changes invisible pink unicorns to purple.

You shut up and get Decadence up again! Stop playing with my heart.
That is a very silly way to reverse a string.
Real men solve those as puzzles, not binary, :P
Garthor wrote:
That is a very silly way to reverse a string.

It is a pretty silly way to reverse a string, but it's kind of amusing that it works.

And the fact that it works using only local comparisons means that it's actually a convenient algorithm in some situations - never for actual real programming, but for programming-based games where you're building some kind of finite state machine or equivalent, it's actually a sensible way to do things.