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

22
2018/07/part1.js Normal file
View file

@ -0,0 +1,22 @@
const fs = require('fs');
let rules = fs.readFileSync('input.txt', 'utf-8').split('\n');
steps = [];
for (let rule of rules) {
[_, step1, step2] = rule.match(/Step (\w) must be finished before step (\w) can begin./);
if (!steps[step1])
steps[step1] = []
if (!steps[step2])
steps[step2] = []
steps[step2].push(step1)
}
let ans = '';
while (Object.entries(steps).length > 0) {
let step = Object.entries(steps).filter(v => v[1].length == 0).map(v => v[0]).sort()[0]
delete steps[step];
for (let step_ in steps) {
steps[step_] = steps[step_].filter(v => v != step)
}
ans += step
}
console.log(ans)