Skip to content

Instantly share code, notes, and snippets.

@Kiwka
Last active December 2, 2019 20:42
Show Gist options
  • Save Kiwka/2c7cdf5bef080349805c288c881a7001 to your computer and use it in GitHub Desktop.
Save Kiwka/2c7cdf5bef080349805c288c881a7001 to your computer and use it in GitHub Desktop.
Advent of Code - 2019 - Day 2
// part 1
const array = $0.textContent.split(',').map(Number);
array[1] = 12;
array[2] = 2;
let i = 0;
while (i < array.length) {
const current = array[i];
if (current === 99) break;
if (current === 1) {
array[array[i+3]] = array[array[i+1]] + array[array[i+2]];
i += 4;
}
if (current === 2) {
array[array[i+3]] = array[array[i+1]] * array[array[i+2]];
i += 4;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment