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.

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.

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.

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

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