Unable to load image

ADVENT OF CODE DAY 11: MONKEY BUSINESS :marseymonke:

Those FRICKING monkeys stole your stuff! Get it back! :soycry: :!marseymonke:

(Also, remember to leave a comment if you did something interesting :marseylove:)

35
Jump in the discussion.

No email address required.

let pop = s => {
  if (s === 'old * old')return a=>a*a
  let q = /^old \* (\d*)$/.exec(s); if (q) return a=>a*(+q[1])
  q = /^old \+ (\d*)$/.exec(s); if (q) return a=>a+(+q[1])
}
let p2 = true
let s = fs.readFileSync('/tmp/input','utf8').split('\n\n').map(a=>/Monkey .*:\n *Starting items: (?<items>.*)\n *Operation: new = (?<op>.*)\n *Test: divisible by (?<div>.*)\n *If true: throw to monkey (?<true>.*)\n *If false: throw to monkey (?<false>.*)/.exec(a).groups).map(a=>({...a, items: a.items.split(', ').map(a=>+a), op: pop(a.op), act: 0}))
let modulo = s.map(a=>a.div).reduce((a,b)=>a*b)
for (let x = 0; x < (p2 ? 10000 : 20); x++)
for (let m of s) {
  for (let i of m.items) {
    m.act++
    i = m.op(i)
    if (!p2) i = floor(i/3)
    else i %= modulo
    s[i%m.div === 0 ? m.true : m.false].items.push(i)
  }
  m.items = []
}

let q = s.map(a=>a.act).sort((a,b)=>a-b)
let out = q.at(-1)*q.at(-2)

the above has two main sources of bloat: writing out the parser instead of just doing 'eval("old => " + op)' bc eval BAD and actually parsing with a big regex instead of just a.split('\n')[3].slice(5) or whatever

why do they need to create retarded narratives? it's just a 'throwing numbers around in a datastructure problem' that has nothing to do with monkeys. they've all been very boring so far, hopefully it'll get better.

Jump in the discussion.

No email address required.

This is just a dumb brute force solution that's been written out in the most boring way possible. It's not even close to the best solution and it's just a waste of time.

Jump in the discussion.

No email address required.

hey @bbbb what's the big(O) of @ejrqiowae89q8h9 's solution?

Jump in the discussion.

No email address required.

Hey you, what's the big deal with your solution? It's O(1), which is obviously not as good as my solution.

Jump in the discussion.

No email address required.

darn @bbbb has got solutions faster than O(1)?!

Jump in the discussion.

No email address required.

Yeah, well I'm not fricking O(1), so get used to it.

Jump in the discussion.

No email address required.

who r u fricking @bbbb?

Jump in the discussion.

No email address required.

I'm fricking you, you fricking idiot.

Jump in the discussion.

No email address required.

darn really? shit i almost forgot. don't worry, i'll hit u back later @bbbb

Jump in the discussion.

No email address required.

More comments

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

Jump in the discussion.

No email address required.

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