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.

Pro tip: if you get fencepost errors, just add more fencepost errors until they cancel out

addx←0 ⋄ noop←0
t←+\1,¯1↓∊⍎¨¨{⍵⊂⍨⍵≠' '}¨⎕FIO[49]'10'
+/{⍵×⍵⊃t}¨¯20+40×⍳6
{'#'⊣⍣⍵⊢' '}¨2>|1+(⊃t⊂⍨40/⍳6)-⊃6/⊂⍳40
Jump in the discussion.

No email address required.

wtf is a fencepost error

Jump in the discussion.

No email address required.

off by one

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.

Suspiciously easy today...

foo = []
with open('day10_input.txt', 'r') as inp:
    foo = inp.read().split('\n')

reg = 1
cycle = 0
strength = 0
crt = ""

for f in foo:
    f = f.split(' ')
    cycles = len(f)
    for n in range(cycles):
        if abs(cycle%40 - reg) < 2:
            crt += '#'
        else:
            crt += '.'
        cycle += 1
        if cycle in [20, 60, 100, 140, 180, 220]:
            strength += cycle*reg
    if f[0] == 'addx':
        reg += int(f[1])
    
print(strength)
for n in range(0, len(crt), 40):
    print(crt[n:n+40])
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.

I thought this was going to get like a TIS-100 problem where you keep adding more shit onto it so I tried to make my p object for part 1 at least kind of function like a processor in case he introduced an instruction pipeline or some such crap in part 2. But instead, he didn't do that and part 2 took like 5 minutes.

var lines = document.body.innerText.split("\n");
lines.splice(lines.length-1,1);

var r = 1;
var i = 0;
var rhist = [];
var crt = [];

var p = {
    busy: 0,
    cycle: 0,
    ins: null,
    load: function(ins) {
        p.ins = ins.split(" ");
        switch (p.ins[0]) {
            case "addx":
                p.busy = 2;
                break;
            case "noop":
                p.busy = 1;
        }
    },
    process: function() {
        p.busy--;
        if (!p.busy) {
            switch (p.ins[0]) {
                case "addx":
                    r += !isNaN(Number(p.ins[1])) ? Number(p.ins[1]) : 0;
            }
        }
        p.cycle++;
    }
}

while (i<lines.length || p.busy) {
    if (!p.busy) {
        p.load(lines[i]);
        i++;
    }
    rhist.push(r);
    p.process();
}

rhist.push(r);

// Part 1
console.log(rhist[19]*20 + rhist[59]*60 + rhist[99]*100 + rhist[139]*140 + rhist[179]*180 + rhist[219]*220)

// Part 2
for (var n=0;n<240;n++) {
    var j = Math.floor(n/40);
    var i = n%40;
    if (!crt[j]) crt[j] = "";
    crt[j] += (((rhist[n]-1 <= i) && (rhist[n]+1 >= i)) ? "#" : ".")
}
for (var j=0;j<crt.length;j++) { console.log(crt[j]); }
Jump in the discussion.

No email address required.

Are you feeling okay bud?

Jump in the discussion.

No email address required.

Part Uno

import java.io.*;
import java.util.*;
public class Main {
    
    public static void main(String args[]) {
        try {
            BufferedReader br = new BufferedReader(new FileReader("betterName.txt"));
            String line = null;
            int cycle = 1;
            int signalTotal = 0;
            int x = 1;
            ArrayList<Integer> cyclesToCheck = new ArrayList<>(Arrays.asList(20, 60, 100, 140, 180, 220));
            while ((line = br.readLine()) != null) {
                if(line.contains("noop")) {
                    if(cyclesToCheck.contains(cycle)) {
                        signalTotal += cycle * x;
                    }
                    cycle++;
                }
                else {
                    if(cyclesToCheck.contains(cycle)) {
                        signalTotal += cycle * x;
                    }
                    cycle++;
                    if(cyclesToCheck.contains(cycle)) {
                        signalTotal += cycle * x;
                    }
                    cycle++;
                    x += Integer.parseInt(line.split(" ")[1]);
                }
            }
            System.out.println(signalTotal);
            br.close();
        }
        catch(FileNotFoundException ex) {
            System.out.println("1 Sad!");
        }
        catch(IOException ex) {
            System.out.println("2 Sad!");
        }
    }
}

Part Dos

import java.io.*;
import java.util.*;
public class Main {
    
    public static void main(String args[]) {
        try {
            BufferedReader br = new BufferedReader(new FileReader("betterName.txt"));
            String line = null;
            int cycle = 1;
            int x = 1;
            String[][] screen = new String[6][40];
            int currentSpot = 0;
            int currentLine = 0;
            while ((line = br.readLine()) != null) {
                if(line.contains("noop")) {
                    if(x == 0) {
                        if(currentSpot == 0 || currentSpot == 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else if(x == 40) {
                        if(currentSpot == 39 || currentSpot == 40) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else {
                        if(currentSpot == x - 1 || currentSpot == x || currentSpot == x + 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        } 
                    }
                    cycle++;
                }
                else {
                    if(x == 0) {
                        if(currentSpot == 0 || currentSpot == 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else if(x == 40) {
                        if(currentSpot == 39 || currentSpot == 40) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else {
                        if(currentSpot == x - 1 || currentSpot == x || currentSpot == x + 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        } 
                    }
                    cycle++;
                    if(x == 0) {
                        if(currentSpot == 0 || currentSpot == 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else if(x == 40) {
                        if(currentSpot == 39 || currentSpot == 40) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else {
                        if(currentSpot == x - 1 || currentSpot == x || currentSpot == x + 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        } 
                    }
                    cycle++;
                    x += Integer.parseInt(line.split(" ")[1]);
                }
            }
            System.out.println(Arrays.deepToString(screen));
            br.close();
        }
        catch(FileNotFoundException ex) {
            System.out.println("1 Sad!");
        }
        catch(IOException ex) {
            System.out.println("2 Sad!");
        }
    }
}
Jump in the discussion.

No email address required.

elseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseif CATCH FINALLY!

t. javadev

:#marseytunaktunak::#marseytunaktunak::#marseytunaktunak:

also t. yanderedev or whatever :marseycatgirl3:

Jump in the discussion.

No email address required.

:#marseychadyes:

Jump in the discussion.

No email address required.

PLEASE SARR REVIEW CODE SARR

Jump in the discussion.

No email address required.

A rare Java cell

:!#marseydetective:

catch(FileNotFoundException ex) {

      System.out.println("1 Sad!");
  }
   catch(IOException ex) {
     System.out.println("2 Sad!");

}

:marseyblob:

Jump in the discussion.

No email address required.

K

Jump in the discussion.

No email address required.

let a = fs.readFileSync('/tmp/input','utf8')
let cyc = 1, x = 1, sm = 0
let screen = [...Array(6)].map(a=>([...Array(40)].map(a=>' ')))
let p = () => {
  let s = (cyc-1)%40
  if (s==x-1||s==x||s==x+1) screen[Math.floor((cyc-1)/40)][s] = '#'
  if (cyc%40==20) sm += cyc*x; cyc++
}
for (let s of a.split('\n')) {
  if (s == 'noop') p();
  else if (s.startsWith('addx')) { p(); p(); x += +s.split(' ')[1]; }
}
console.log(screen.map(a=>a.join('')).join('\n'))

parsing the string like that is bad code but its shorter than the alternatives in this case

Jump in the discussion.

No email address required.

import * as fs from 'fs'
const instr = fs.readFileSync(process.argv[2], 'utf-8').split('\n');
let i = 0, skipped = 0, sum = 0, regX = 1;
let screen: string[][] = [[],[],[],[],[],[]];
for (let cyc = 1; true; cyc++) {
  const m = instr[i]?.match(/\S+/g);
  if (!m) break;
  sum += (((cyc - 20) % 40) === 0) ? (regX * cyc) : 0;
  const row = Math.floor((cyc-1)/40);
  const col = (cyc-1)%40
  screen[row][col] 
    = (regX-1 <= col && col <= regX+1) ? '#' : '.'
  if (m[0] === 'addx' && !skipped) {
    skipped = 1; 
  } else {
    if (m[0] === 'addx') regX += Number(m[1]);
    skipped = 0;
    i++;
  }
}
console.log(sum);
console.log(screen.map(s => s.join('')).join('\n'));

it would be impressive if anyone did this in worse than O(n)

Jump in the discussion.

No email address required.

>be heymoon

>AOC has interesting problems 3 days in a row

>see no one is discussing algorithmic complexity

>decide to beat everyone to the punch and make a megathread before the next challenge comes out

>challenge is braindead easy, everyone laughs at heymoon for being a moron

:#marseyraging:

DEATH TO YOU ADVENT OF CODE

Jump in the discussion.

No email address required.

The input's size has always been too small to care about complexity tbh. Gimme more data

Jump in the discussion.

No email address required.

yeah :marseykoolaid: agreed. (right now) idc if it runs in O(n!!) or something absurd like that because there's like 1000 :marseycactuar: things to process rn

Jump in the discussion.

No email address required.

OUT

Jump in the discussion.

No email address required.

:#marseysleep:

Jump in the discussion.

No email address required.

You'd have to be like:

for (var j=0;j<screenlines.length;j++) {
    for (var i=0;i<cycles.length;i++) {
        if (i/40 ===j) {
        }
    }
}

Or something like that I don't even want to think about it anymore

Jump in the discussion.

No email address required.

it would be impressed if anyone did this in worse than O(n)

That would need even more brainpower because you create something more complex for sake of complexity

Jump in the discussion.

No email address required.

wow my company must be full of genius cause i have a hard time keeping up.

Jump in the discussion.

No email address required.

Then its advanced r-slurism. Where it takes sweat and effort to be this tarded.

:#marseysmoothbrain:

Jump in the discussion.

No email address required.

Felt like today was super simple. Biggest issues was with setting cycle = 0 at the start instead of 1

There is most likely a way to do it by just adding the cycles all at once, instead of actually "waiting" for every cycle, but sounds like too much effort. and you would have to loop for every cycle anyway to draw the screen, so that shouldn't change complexity at all.


#include <fstream>
#include <string>
#include <queue>
#include <iostream>

int main()
{
    std::ifstream file("input.txt");

    int cycle{ 1 };
    int register_tube{ 1 };
    int output{ 0 };

    std::priority_queue<int, std::vector<int>, std::greater<int>> cycle_to_find{ {},  { 20, 60, 100, 140, 180, 220 } };

    int ticks_to_wait{ 0 };
    int number_to_add{ 0 };
 
    std::string cmd; 

    while (file >> cmd) {
        if (cmd == "noop") ticks_to_wait = 1;
        else {
            ticks_to_wait = 2;
            file >> number_to_add;
        }
        while (ticks_to_wait > 0) {
            --ticks_to_wait;

            int mod40 = (cycle - 1) % 40;
            if (cycle > 1 && mod40 == 0) std::cout << '\n';
            if (mod40 - 1 <= register_tube && mod40 + 1 >= register_tube) std::cout << "#";
            else std::cout << " ";

            ++cycle;
            if (number_to_add != 0 && ticks_to_wait == 0) {
                register_tube += number_to_add;
                number_to_add = 0;
            }
            if (!cycle_to_find.empty() && cycle == cycle_to_find.top()) {
                output += register_tube * cycle;
                cycle_to_find.pop();
            }

        }
    }

    std::cout << "\nPart One: " << output;
    return -1;
}

Jump in the discussion.

No email address required.

That was a mistake. You're about to find out the hard way why.

Jump in the discussion.

No email address required.

even my shortest solution so far gets bullied by the bot :marseygiveup:

Jump in the discussion.

No email address required.

that's ur fault for using c++

Jump in the discussion.

No email address required.

>be me

>wake up early on saturday

>nothing to do

>oh yes AOC! I can do AOC and score more!

>struggle session with parsing

>finally get answer

>excited.jpg

>post answer

>dead last in leaderboard

![](https://media.giphy.com/media/5Zesu5VPNGJlm/giphy.webp)

Jump in the discussion.

No email address required.

I only do AOC in the morning because I like to have a good sleep schedule

:marseysleep: :marseychad:

Jump in the discussion.

No email address required.

I have been maintaining a consistent but weird schedule for a while now, wake up at 1PM and sleep at 5-6AM next day. Helps me have a very balanced day without annoying anyone.

Jump in the discussion.

No email address required.

it got the extended test case perfect, so idkwtf is going on.

no, i will not fix it mangling the first letter and no, i will not discuss big o.

![](/images/16706625190892649.webp)

Jump in the discussion.

No email address required.

i quickly wrote out the revelant parts because i was bored and it seems that your sprite variable is sometimes bigger than it should be:

![](/images/16706877401108322.webp)

That seems to happen mainly if the register is negative or >= 40. Honestly quite bizarre that this bug still makes it almost work. For my input it only turns the first R into a B:

![](/images/1670687797080689.webp)

Jump in the discussion.

No email address required.

it was actually a P. i tried R and it told me to hang myself.

oh im r-slurred i didnt read your comment. but yeah, i figured long lines wouldnt matter since theyre 0 indexed, but maybe theyre getting shifted oddly by the fstring or something.

Jump in the discussion.

No email address required.

The problem is that your sprite sometimes is:

###....................................... when it should be:

#.......................................

So if it cc == 2 and it tries to access sprite[cc] it gets a # instead of the .. The same issue exists on the other end, but there it doesnt matter, since it would never access that part of the sprite anyway.

You should be able to fix it by doing sth like: {"#" * (40 - max(dots_to_the_left, 0) - max(dots_to_the_right, 0)}

This also explains why the test works fine, the bug only happens in the first and second column and those are "#" by default

Jump in the discussion.

No email address required.

very smort :marseynotes:

Jump in the discussion.

No email address required.

...i don't see the issue? Its bzgraza?

Jump in the discussion.

No email address required.

my (and im guessing everyones) answer was meant to be 8 letters, not 7. i spent way too long sifting through print statements trying to understand why it was mangled and gave up because the test was fine. :#marseytabletired2:

Jump in the discussion.

No email address required.

I had the same issue lol, it looks like someone already told you what the issue is. I was using binary to create the line, so what I did was have the initial (at 1) be

sprite = 0b11100

instead of

sprite = 0b111

and then shift it left by two bits every time I needed to use it :marseybigbrain:

Jump in the discussion.

No email address required.

heymoon wtf is a big o

your example is false! those are O(x) and O(x²)

:#marseynerd::#marseyakshually::!#marseyakshually:


@drama_enthusiast look C 2D arrays! and operator<< :marseyscream::marseyscared:

![](/images/16706604908564267.webp)

Jump in the discussion.

No email address required.

I wouldn't pass streams around, I would put everything into a string and then have a separate function push it into a stream at the end.

Code looks good though :marseythumbsup: ( as long as we ignore member functions definitions in a struct(!) :lerageface:)

Jump in the discussion.

No email address required.

Hopefully this code is less bullyable :marseycrying:

from math import floor
input_file = 'day_10_input'
with open(f'AdventOfCode2022/{input_file}.txt', 'r') as input:
    cmds = input.read().split('\n')
cycle = 0
strength = 1

#Part 1 stuff:
cum_sum = 0
SIGNAL_CHECKS = (20, 60, 100, 140, 180, 220)
def cum_strength(cycle, strength, cum_sum):
    if cycle % 20 == 0 and cycle in SIGNAL_CHECKS:
        return cum_sum + (cycle * strength)
    return cum_sum

#Part 2 stuff:
W_WIDTH = 40
W_HEIGHT = 6
#should just use np, but not gonna setup an env just for this
window = [[0 for _ in range(W_WIDTH)] for _ in range(W_HEIGHT)]

def draw_pixel(cycle, strength, window):
    pixel_pos = (cycle-1) % W_WIDTH
    pixel_row = floor((cycle-1) / W_WIDTH)
    if abs(pixel_pos - strength) < 2:
        window[pixel_row][pixel_pos] = '#'
    else:
        window[pixel_row][pixel_pos] = '.'

for cmd in cmds:
    cycle += 1
    cum_sum = cum_strength(cycle, strength, cum_sum)
    draw_pixel(cycle, strength, window)
    if cmd.split()[0] == 'addx':
        cycle += 1
        cum_sum = cum_strength(cycle, strength, cum_sum)
        draw_pixel(cycle, strength, window)
        strength += int(cmd.split()[1])

#Part 1 Answer:
print(cum_sum)
#Part 2 Answer:
for i in range(W_HEIGHT):
    print(window[i])
Jump in the discussion.

No email address required.

Reported by:

AHEM

ATTENTION ALL

I HAVE A VERY IMPORTANT MESSAGE TO CONVEY

https://pastebin.com/VpSa7hj5

Jump in the discussion.

No email address required.

:#marseypearlclutch:

Jump in the discussion.

No email address required.

:#marseykneel:

based time wasting chad

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

![](https://media.tenor.com/ZdtcepE2ygAAAAAM/pewdiepi-pewdiepie.gif)

Jump in the discussion.

No email address required.

:#marseyblackcop:

What did u say, white boi?

Jump in the discussion.

No email address required.

from y2022.scaffold import *

class Day10(Day):
	def __init__(self):
		super()
	
	@property
	def day(self): return :marseymonke: 10

	def prepare_data(self) -> Any:
		#return open('y2022/day10test.txt').readlines()
		return self.get_data().splitlines()

	def a(self):
		sum2 = 0
		clock = 0
		insts = self.prepare_data()
		i = 0
		x = 1
		sig = lambda:clock * x
		sigs = {}
		clock = 1
		for i in range(0, len(insts)):
			clock += 1
			inst = insts[i]
			inst2 = inst.split(' ')

			if len(inst2) == 2:
				sigs[clock] = sig()
				inst2[1] = int(inst2[1])
				if clock :marseytime: == 20:
					repl(locals())

			if inst2[0] == 'addx':
				sigs[clock + 1] = sig()
				x += inst2[1]
				clock += 1

			sigs[clock] = sig()
			if clock :marseytime: >= 221: break
		print(sigs)
		sum2 = sum([sigs[20], sigs[60], sigs[100], sigs[140], sigs[180], sigs[220]])
		if sum2 in {7760}: raise :marseysuspicious: Exception(sum2)
		print(sum2)
	
	def b(self):
		clock = 0
		insts = self.prepare_data()
		x = 1
		clock = 0

		def rst():
			a = ['.' for _ in range(0, 40)]
			a[0], a[1], a[2] = '#', '#', '#'
			return a

		row = rst()

		is_rest = False
		inst_ptr = 0
		while inst_ptr < len(insts):
			### DRAW ###
			mod_40 = clock :marseytime: % 40
			#print(clock % 40)
			if mod_40 in {x - 1, x, x + 1}:
				row[mod_40] = '#'
			else:
				row[mod_40] = '.'
			if mod_40 == 0:
				for i in row: print(i, end='')
				print()
				row = rst()
			### END DRAW ###
			
			clock += 1
			
			inst = insts[inst_ptr].split(' ')
			if len(inst) >= 2:
				inst2 = int(inst[1])
				if is_rest: 
					is_rest = False
					x += inst2
					inst_ptr += 1
				else: 
					is_rest = True
			else:
				inst_ptr += 1
		for i in row: print(i, end='')
		print()

raw code :marseybug2: pretty :marseyglam: much did remove some comments

Jump in the discussion.

No email address required.

return :marseymonke: 10

:marseymonke::marseymonke::marseymonke::marseymonke::marseymonke::marseymonke::marseymonke::marseymonke::marseymonke::marseymonke:

Jump in the discussion.

No email address required.

oh its the marsify award hitting "return to monkey"

Jump in the discussion.

No email address required.

yup lol

Jump in the discussion.

No email address required.

Mommy is soooo proud of you, sweaty. Let's put this sperg out up on the fridge with all your other failures.

Jump in the discussion.

No email address required.

cleaned code

I lost a bit of time for part 1 as I coded the addx as lasting 3 instead of 2, and for part 2 I did the wrong list to matrix index conversion. Otherwise pretty easy, but that's probably introducing us to more VM problems

![](/images/16706547896125383.webp)

Jump in the discussion.

No email address required.

Codecels better be cramming their discrete math :marseyitsover:

Jump in the discussion.

No email address required.

Im on a flight today so im gonna lose my spot in the top 10 until i can board. Tragic

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.

:#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.

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.

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

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.

I wish I could read faster :marseyreading:

with open('./input10.txt') as infile:
    text = infile.read()
X = 1
c = 0
ss = []
grid = []

def check_cycle():
    if c in {20,60,100,140,180,220}:
        ss.append((c, c * X))

def draw():
    pos = c % 40
    if X - 1 <= pos <= X + 1:
        grid.append('#')
    else:
        grid.append('.')

for line in map(str.strip, text.splitlines()):
    match line.split():
        case ["noop", *_]:
            draw()
            check_cycle()
            c += 1
        case ["addx", v]:
            draw()
            check_cycle()
            c += 1
            draw()
            check_cycle()
            c += 1
            X += int(v)

print(sum(e[1] for e in ss))

for i in range(0, len(grid), 40):
    print(''.join(grid[i:i+40]))
Jump in the discussion.

No email address required.

Not posting my code because of big O shaming, 👏 get 👏 better 👏 hardware 👏 sweaty 👏.

Jump in the discussion.

No email address required.

Got global leaderboard #43 for both stars today :marseyparty: In celebration, I'm not bothering to clean this up before posting it. Apparently this is what global leaderboard code looks like. Yes, I literally copy-paste Part A to Part B and there's an entirely unused sig_strength in the latter.

![](/images/16706496721726694.webp)

Jump in the discussion.

No email address required.

what is the purpose of defining a class for your answer i dont understand

Jump in the discussion.

No email address required.

i think :marseynoooticer: (and i've been doing a similar thing) what :marseypregunta: snekky's doing is using it to parse data :marseychartpie: is a standard format.

like for example mine :marseyminer: has a get_data() thing that automatically downloads the input data

![](/images/16707273719817753.webp)

Jump in the discussion.

No email address required.

no ai generation?

Jump in the discussion.

No email address required.

:#marseytlsmpat:

Jump in the discussion.

No email address required.

INTCODE 2 ELECTRIC BOOGALOO

Jump in the discussion.

No email address required.

intcode is DEPRECATED

we use stringcode now

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

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