NERD SHIT :marseynerd: ADVENT OF CODE 10 M=E=G=A=T=H=R=E=A=D

LET'S SAVE THOSE ELVES, BROS

Okay it isn't even out yet, I'm sure it will be great, and the elves are in trouble, etc. I'm just beating you all to the bunch so I can tell you to explain your answers, we care about ALGORITHMIC COMPLEXITY now. What's the fastest and most efficient way to do it.

heymoon wtf is a big o

This is O(n)

x = REALLY_BIG_NUMBER
for i in range(x):
    process(i)

This is O(n^2)

x = REALLY_BIG_NUMBER
for i in range(x):
    for j in range(x)
        process(i,j)

There's more to it but that's the quick version. Also there are things like O(log(n)) (based), O(a^n) (cringe), and O(n!) (advanced cringe).

Okay, post ur code too but explain why its cool or no one will read it. I'll pin my favorite answers, other mods also do this

LET'S SAVE THOSE ELVES, BROS

42
Jump in the discussion.

No email address required.

how the fuck am i supposed to know what the algorithmic complexity of my code is? i'm not quite autistic enough to care, so don't answer

got stuck on part 2 for a while because i forgot % 40

with open("day10input.txt") as f:
    input = f.read().split("\n")

# part 1

x = 1
cycles = 0
answer = []
for line in input:
    match line.split(" "):
        case ["noop"]:
            cycles += 1
            if (cycles - 20) % 40 == 0:
                answer.append(x * cycles)
        case ["addx", v]:
            for _ in range(2):
                cycles += 1
                if (cycles - 20) % 40 == 0:
                    answer.append(x * cycles)
            x += int(v)

print(sum(answer))

# part 2 

x = 1
cycles = 0
drawing = []

for line in input:
    match line.split(" "):
        case ["noop"]:
            if cycles % 40 in (x-1, x, x+1):
                drawing.append("#")
            else:
                drawing.append(".")
            cycles += 1
        case ["addx", v]:
            for _ in range(2):
                if cycles % 40 in (x-1, x, x+1):
                    drawing.append("#")
                else:
                    drawing.append(".")
                cycles += 1
            x += int(v)

lines = [drawing[:40], drawing[40:80], drawing[80:120], drawing[120:160], drawing[160:200], drawing[200:]]
for line in lines:
    print("".join(line))
Jump in the discussion.

No email address required.

how the frick am i supposed to know what the algorithmic complexity of my code is?

Jesus you're really ngmi. Are you a hobby dev?

Jump in the discussion.

No email address required.

Most performance aware pythonista

Jump in the discussion.

No email address required.

Moore's law means hardware gets better faster than I need resources. Even if I somehow max it out, I just turn around for a second, order a new part and I'm back to blissful ignorance.

Jump in the discussion.

No email address required.

banned

Jump in the discussion.

No email address required.

Ruuuuuude!

:marseyban::marseytears:

Jump in the discussion.

No email address required.

this :marseysharksoup: has been what :marseyidk: has led to the current state :marseycoonass: of web development

Jump in the discussion.

No email address required.

:#marseynerd2:

Jump in the discussion.

No email address required.

lol, i mean ... i get paid to do this shit, and big O awareness absolutely essential to not producing absolute dogshit as code, like most my coworkers.

but i'm not neurodivergent enough to code as a hobby.

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.