2018 d8 p1
This commit is contained in:
parent
2e77fcf631
commit
72eda129d2
21
2018/8/part1.js
Normal file
21
2018/8/part1.js
Normal 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
4
2018/8/test.txt
Normal 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
4
2018/8/test1.txt
Normal 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 -
|
|
@ -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/5 "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. [-](https://adventofcode.com/2015/day/8 "see puzzle")
|
||||
1. [js :star: :star:](https://adventofcode.com/2015/day/7 "see puzzle")
|
||||
1. [js :star:](https://adventofcode.com/2015/day/8 "see puzzle")
|
||||
|
||||
# Languages Used
|
||||
### Python
|
||||
|
@ -23,3 +23,4 @@
|
|||
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/7 "see puzzle")
|
||||
1. [:star:](https://adventofcode.com/2018/day/8 "see puzzle")
|
||||
|
|
|
@ -14,7 +14,7 @@ if (advent) {
|
|||
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/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")
|
||||
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/6 "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
|
||||
* Python 8×:star:
|
||||
|
|
Loading…
Reference in a new issue