renamed 2 digit file names

This commit is contained in:
Tristan 2018-12-10 23:56:11 +00:00
parent 018011dd27
commit b4d985a55a
44 changed files with 0 additions and 0 deletions

1
2018/08/input.txt Normal file

File diff suppressed because one or more lines are too long

20
2018/08/part1.js Normal file
View file

@ -0,0 +1,20 @@
const fs = require('fs');
const input = fs.readFileSync('input.txt', 'utf-8').split('\n')[0].split(' ').map(Number);
function parse(arr) {
if (arr[0] == 0) {
return ([2 + arr[1], arr.slice(2, 2 + arr[1])]);
}
let meta = []
let pointer = 2;
for (let i = 0; i < arr[0]; i++) {
let child = parse(arr.slice(pointer, arr.length));
pointer += child[0];
meta = meta.concat(child[1]);
}
meta = meta.concat(arr.slice(pointer, pointer + arr[1]))
return [pointer + arr[1], meta];
}
let v = parse(input)[1];
console.log(v.reduce((a, b) => a + b));

24
2018/08/part2.js Normal file
View file

@ -0,0 +1,24 @@
const fs = require('fs');
const input = fs.readFileSync('input.txt', 'utf-8').split('\n')[0].split(' ').map(Number);
function parse(arr) {
if (arr[0] == 0) {
return ([2 + arr[1], arr.slice(2, 2 + arr[1]).reduce((a, b) => a + b)]);
}
let children = [];
let pointer = 2;
for (let i = 0; i < arr[0]; i++) {
let child = parse(arr.slice(pointer, arr.length));
pointer += child[0];
children.push(child[1]);
}
let meta = 0;
let indexes = arr.slice(pointer, pointer + arr[1])
for (let i of indexes) {
meta += children[i - 1] || 0;
}
return [pointer + arr[1], meta];
}
let v = parse(input)[1];
console.log(v);

4
2018/08/test.txt Normal file
View file

@ -0,0 +1,4 @@
2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2
A-----------------------------1-1-2
B---10-11-12 C----------2
D---99

4
2018/08/test1.txt Normal file
View file

@ -0,0 +1,4 @@
3 2 1 1 0 0 5 0 3 1 2 3 1 0 0 0 67 67
A ----------------------------- 67 67
B ------5 C --1-2-3 D------
C-- E--