What's the stupidest/most roundabout/most inefficient code you wrote when you were first learning to program?

What's the stupidest/most roundabout/most inefficient code you wrote when you were first learning to program?
I really wanted to get into game development, so I skipped the basics of programming and jumped right into gamedev (big mistake, I know). I tried to make an AABB function that worked by drawing an invisible box around the object and checking it for collision.
Still don't know why I thought that would work.

Exponential regex matching algorithm

Recursive Fibonacci.

We learned to program GBA in our intro computer architecture class, and I completely forgot about DMA and I moved pixels into and out of memory using for loops.

Heat equation

//inverting the value of a boolean
if(bool_var == true){
bool_var = false
}else{
bool_var = true
}

I still remember the joy of that day when I discovered
bool_var = !bool_var

wait you can do that?

Why not?

assignment was to write a snowy scene in SDL, basically make snowflakes fall down over a drawing of a wooden house. looked comfy etc. only needed to make them fall vertically but I used a sin curve with a random offset so that they'd swerve.

problem is I'd just keep loading new instances of the same sprite for every snowflake I spawned. result; the animation ran for 30 seconds or so until the shitty school computer ran out of VRAM and the program crashed.

hilariously, I showed my instructor, and he was fucking clueless. I had to figure it out on my own because the genius decided to make us use SDL before we knew what pointers even were. that was the first of many disappointments that eventually made me drop out.

bool_var = bool_var == true ? false : true;

if(statement == true) {
return true;
} else {
return false;
}

I once wrote simple Basic in Basic. I could read and write to files, had all the loops and shit..

And that was superslow. And that time i... decided to rewrite it in C.

Then I broke it.

looks fine?

just do `return statement`

return statement == true;is good enough.

underrated post

When I first heard about Python, I only knew C, so I programmed in Python like I would in C, fuck it.
# Integrates only positive values of sin(x).
def integrateSin(N, a, b):
integral = 0.0
t = 0.0
for i in range(N):
t = sin(a * (1.0 - i / (N - 1)) + b * i / (N - 1))
if t > 0.0:
integral += t
return (b - a) * integral / N


Then people told me that's fucking retarded (I thought it should be efficient, I didn't really realize back then how Python is supposed to work – more like a meta language to handle algorithms implemented in real languages). It was really awkward to me at first, but then finally I got around using stuff like
# Integrates only positive values of sin(x).
def integrateSin(N, a, b):
y = np.sin(np.linspace(a, b, N))
return (b - a) * np.sum(y[y > 0.0]) / N

(It's a stupid example of course, but it's just supposed to illustrate the general problem)
But to this day I think it takes away all the fun in programming to think like that.

this is why i hate python its like... not programming. my calculator is more readable and reliable than this crap.

have you ever seen the debates on Sup Forums about mathematical order of operations? they rage on for days sometimes!!!

I had just started to program, but still it's pretty stupid and I still wonder how I managed it:

I was trying to write a function to check if a number was a palindrome. Rather of getting the digits and comparing them, instead I used the C++ standard library to convert the int to a string, then split it into two based on its length, used the standard library function to reverse one of the strings, and then compared them.

What's a use case scenario for inverting a bool? Why can't you just make your function or functions return the inverted value, or use the non inverted value normally further on?

I really liked to write something along the lines of
while(true == true&& 1 != 2 || false != false || 4*4!=546)
{
// whatever
}

shiiet, i made a typo with my brilliant code!

I actually doubt that the string version is much slower than the digit extraction etc. I'd even say if you don't do any completely redundant stuff it's probably faster then the more straight-forward solution as the shit from the standard libraries is super optimized (and if you think about it, it pretty much does EXACTLY what the digit comparison does).

That's true. The int to string function they use is probably much faster than my preferred method of dividing by 10 repeatedly

what if statement is a string, for instance?

CS freshmen meme general

#include
#include

bool is_palindrome(int n)
{
std::string number = std::to_string(n);
return std::equal(number.begin(), number.end(), number.rbegin());
}

int main(int argc, char **argv)
{
std::cout

something similar happened to me
>Wrote a console game of the Hanoi Tower (pic related)
>Without knowing shit of IA or algorithms try to code a self solving algorithm for any level of difficulty
>Wrote a super complicated, inneficient, long, incomprensible, no functional code of about 300 lines that "apparently" solve the game...
>Made a little research... realize that people challenge each other to make the most simple and fast hanoi tower algorithm... using recursive functions they solve the steps in 3 lines of code...
>Feel like shit...