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.

late because I'm not paying for the :marseymerchant: psyop that is airplane wifi plans

file = open("input.txt")
pipeline = [0]*500
tocheck = [20, 60, 100, 140, 180, 220]
row = ["."] * 240
ptr = 0
x = 1
clock = 0
ans = 0
for line in file:
    op = line.rstrip().split()
    if op[0] == "addx":
        ptr+=2
        pipeline[ptr-1] = x
        x+= int(op[1])
        pipeline[ptr] = x
    elif op[0] == "noop":
        ptr += 1
        #print(ptr)
        pipeline[ptr] = x

for i in tocheck:
    ans += pipeline[i-1]*i
    
for i in range(0, 240):
    if abs(pipeline[i] - (i%40)) <= 1:
        row[i] = "#"
    print(row[i], end =" ")
    if i % 40 == 39: print("\n")

        
print(ans )
Jump in the discussion.

No email address required.

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