2018 d8 p1

This commit is contained in:
Tristan 2018-12-09 00:37:33 +00:00
parent 2e77fcf631
commit 72eda129d2
5 changed files with 34 additions and 4 deletions

21
2018/8/part1.js Normal file
View file

@ -0,0 +1,21 @@
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) {
debugger;
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));

4
2018/8/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/8/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 -

View file

@ -5,8 +5,8 @@
1. [js :star: :star:](https://adventofcode.com/2015/day/4 "see puzzle") 1. [js :star: :star:](https://adventofcode.com/2015/day/4 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/5 "see puzzle") 1. [js :star: :star:](https://adventofcode.com/2015/day/5 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/6 "see puzzle") 1. [js :star: :star:](https://adventofcode.com/2015/day/6 "see puzzle")
1. [js :star:](https://adventofcode.com/2015/day/7 "see puzzle") 1. [js :star: :star:](https://adventofcode.com/2015/day/7 "see puzzle")
1. [-](https://adventofcode.com/2015/day/8 "see puzzle") 1. [js :star:](https://adventofcode.com/2015/day/8 "see puzzle")
# Languages Used # Languages Used
### Python ### Python
@ -23,3 +23,4 @@
1. [:star: :star:](https://adventofcode.com/2018/day/5 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/5 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2018/day/6 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/6 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2018/day/7 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/7 "see puzzle")
1. [:star:](https://adventofcode.com/2018/day/8 "see puzzle")

View file

@ -14,7 +14,7 @@ if (advent) {
1. [js :star: :star:](https://adventofcode.com/2015/day/2 "see puzzle") 1. [js :star: :star:](https://adventofcode.com/2015/day/2 "see puzzle")
1. [py :star: :star:](https://adventofcode.com/2015/day/3 "see puzzle") 1. [py :star: :star:](https://adventofcode.com/2015/day/3 "see puzzle")
1. [py :star: :star:](https://adventofcode.com/2015/day/5 "see puzzle") 1. [py :star: :star:](https://adventofcode.com/2015/day/5 "see puzzle")
1. [-](https://adventofcode.com/2015/day/1 "see puzzle") 1. [-](https://adventofcode.com/2015/day/6 "see puzzle")
#### [2018](https://adventofcode.com/2018 "2018 puzzle calendar") #### [2018](https://adventofcode.com/2018 "2018 puzzle calendar")
1. [js :star: :star:](https://adventofcode.com/2015/day/1 "see puzzle") 1. [js :star: :star:](https://adventofcode.com/2015/day/1 "see puzzle")
@ -24,7 +24,7 @@ if (advent) {
1. [js :star: :star:](https://adventofcode.com/2015/day/5 "see puzzle") 1. [js :star: :star:](https://adventofcode.com/2015/day/5 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/6 "see puzzle") 1. [js :star: :star:](https://adventofcode.com/2015/day/6 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/7 "see puzzle") 1. [js :star: :star:](https://adventofcode.com/2015/day/7 "see puzzle")
1. [-](https://adventofcode.com/2015/day/8 "see puzzle") 1. [js :star:](https://adventofcode.com/2015/day/8 "see puzzle")
## Languages Used ## Languages Used
* Python 8&times;:star: * Python 8&times;:star: