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.

For Part 2, I used bit twiddling. The Ray was a "1" that would move across the screen by doing a shift left operation. The sprite was the number '7' (111) (technically 28 because i had two zeros of offset), and the line would be (ray OR sprite).

>b-b-but heymoon that is probably more complicated that it needs to be, you could do it easier if you just kept track of the numbers and built a string that way :soycry:

I don't give a singular fuck :chad: , it's a CRT display and I'm going to model it correctly damnit!

#Assume that sprite can only go to -1. If so, we just do an offset of 2 to preserve the sprite at all times
sprite = 0b11100 #Register starts at 1, but the sprite is three pixel wide.
ray = 0b1
line = 0b0
cycle_number = 1
line_number = 1
instruction_i = 0
currently_executing_add = False
debug = False
while instruction_i < len(lines):
    #Flush
    if cycle_number == 40*line_number +1:
        line_number += 1
        ray = 0b1
        print(format(line, '#042b')[::-1])
        line = 0b0
    
    line = line | (ray & (sprite >> 2))
    cycle_number+=1
    ray = ray << 1

    instruction = lines[instruction_i]
    if 'addx' in instruction:
        if currently_executing_add:
            to_add = int(instruction.split(" ")[1])
            if (to_add >= 0):
                sprite = sprite << to_add
            else:
                sprite = sprite >> abs(to_add)
            currently_executing_add = False
            instruction_i+=1
        else:
            currently_executing_add = True
    else:
        instruction_i+=1
print(format(line, '#042b')[::-1])
Jump in the discussion.

No email address required.

Wow, you must be a JP fan.

Jump in the discussion.

No email address required.

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