day 7
This commit is contained in:
parent
182de3db5f
commit
cbecce98a8
7
07/input-test.txt
Normal file
7
07/input-test.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Step C must be finished before step A can begin.
|
||||||
|
Step C must be finished before step F can begin.
|
||||||
|
Step A must be finished before step B can begin.
|
||||||
|
Step A must be finished before step D can begin.
|
||||||
|
Step B must be finished before step E can begin.
|
||||||
|
Step D must be finished before step E can begin.
|
||||||
|
Step F must be finished before step E can begin.
|
101
07/input.txt
Normal file
101
07/input.txt
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
Step I must be finished before step Q can begin.
|
||||||
|
Step B must be finished before step O can begin.
|
||||||
|
Step J must be finished before step M can begin.
|
||||||
|
Step W must be finished before step Y can begin.
|
||||||
|
Step U must be finished before step X can begin.
|
||||||
|
Step T must be finished before step Q can begin.
|
||||||
|
Step G must be finished before step M can begin.
|
||||||
|
Step K must be finished before step C can begin.
|
||||||
|
Step F must be finished before step Z can begin.
|
||||||
|
Step D must be finished before step A can begin.
|
||||||
|
Step N must be finished before step Y can begin.
|
||||||
|
Step Y must be finished before step Q can begin.
|
||||||
|
Step Q must be finished before step Z can begin.
|
||||||
|
Step V must be finished before step E can begin.
|
||||||
|
Step A must be finished before step X can begin.
|
||||||
|
Step E must be finished before step C can begin.
|
||||||
|
Step O must be finished before step R can begin.
|
||||||
|
Step P must be finished before step L can begin.
|
||||||
|
Step H must be finished before step R can begin.
|
||||||
|
Step M must be finished before step R can begin.
|
||||||
|
Step C must be finished before step Z can begin.
|
||||||
|
Step R must be finished before step L can begin.
|
||||||
|
Step L must be finished before step S can begin.
|
||||||
|
Step S must be finished before step X can begin.
|
||||||
|
Step Z must be finished before step X can begin.
|
||||||
|
Step T must be finished before step O can begin.
|
||||||
|
Step D must be finished before step Z can begin.
|
||||||
|
Step P must be finished before step R can begin.
|
||||||
|
Step M must be finished before step Z can begin.
|
||||||
|
Step L must be finished before step Z can begin.
|
||||||
|
Step W must be finished before step N can begin.
|
||||||
|
Step Q must be finished before step R can begin.
|
||||||
|
Step P must be finished before step C can begin.
|
||||||
|
Step U must be finished before step O can begin.
|
||||||
|
Step F must be finished before step O can begin.
|
||||||
|
Step K must be finished before step X can begin.
|
||||||
|
Step G must be finished before step K can begin.
|
||||||
|
Step M must be finished before step C can begin.
|
||||||
|
Step Y must be finished before step Z can begin.
|
||||||
|
Step A must be finished before step O can begin.
|
||||||
|
Step D must be finished before step P can begin.
|
||||||
|
Step K must be finished before step S can begin.
|
||||||
|
Step I must be finished before step E can begin.
|
||||||
|
Step G must be finished before step F can begin.
|
||||||
|
Step S must be finished before step Z can begin.
|
||||||
|
Step N must be finished before step V can begin.
|
||||||
|
Step F must be finished before step D can begin.
|
||||||
|
Step A must be finished before step Z can begin.
|
||||||
|
Step F must be finished before step X can begin.
|
||||||
|
Step T must be finished before step Y can begin.
|
||||||
|
Step W must be finished before step H can begin.
|
||||||
|
Step D must be finished before step H can begin.
|
||||||
|
Step W must be finished before step G can begin.
|
||||||
|
Step J must be finished before step X can begin.
|
||||||
|
Step T must be finished before step X can begin.
|
||||||
|
Step U must be finished before step R can begin.
|
||||||
|
Step O must be finished before step P can begin.
|
||||||
|
Step L must be finished before step X can begin.
|
||||||
|
Step I must be finished before step B can begin.
|
||||||
|
Step M must be finished before step L can begin.
|
||||||
|
Step C must be finished before step R can begin.
|
||||||
|
Step R must be finished before step X can begin.
|
||||||
|
Step F must be finished before step N can begin.
|
||||||
|
Step V must be finished before step H can begin.
|
||||||
|
Step K must be finished before step A can begin.
|
||||||
|
Step W must be finished before step O can begin.
|
||||||
|
Step U must be finished before step Q can begin.
|
||||||
|
Step O must be finished before step C can begin.
|
||||||
|
Step K must be finished before step V can begin.
|
||||||
|
Step R must be finished before step S can begin.
|
||||||
|
Step E must be finished before step S can begin.
|
||||||
|
Step J must be finished before step A can begin.
|
||||||
|
Step E must be finished before step X can begin.
|
||||||
|
Step K must be finished before step Y can begin.
|
||||||
|
Step Y must be finished before step X can begin.
|
||||||
|
Step P must be finished before step Z can begin.
|
||||||
|
Step W must be finished before step X can begin.
|
||||||
|
Step Y must be finished before step A can begin.
|
||||||
|
Step V must be finished before step X can begin.
|
||||||
|
Step O must be finished before step M can begin.
|
||||||
|
Step I must be finished before step J can begin.
|
||||||
|
Step W must be finished before step L can begin.
|
||||||
|
Step I must be finished before step G can begin.
|
||||||
|
Step D must be finished before step O can begin.
|
||||||
|
Step D must be finished before step N can begin.
|
||||||
|
Step M must be finished before step X can begin.
|
||||||
|
Step I must be finished before step R can begin.
|
||||||
|
Step Y must be finished before step M can begin.
|
||||||
|
Step F must be finished before step M can begin.
|
||||||
|
Step U must be finished before step M can begin.
|
||||||
|
Step Y must be finished before step H can begin.
|
||||||
|
Step K must be finished before step D can begin.
|
||||||
|
Step N must be finished before step O can begin.
|
||||||
|
Step H must be finished before step S can begin.
|
||||||
|
Step G must be finished before step L can begin.
|
||||||
|
Step T must be finished before step D can begin.
|
||||||
|
Step J must be finished before step N can begin.
|
||||||
|
Step K must be finished before step M can begin.
|
||||||
|
Step K must be finished before step P can begin.
|
||||||
|
Step E must be finished before step R can begin.
|
||||||
|
Step N must be finished before step H can begin.
|
16
07/part1.js
Normal file
16
07/part1.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
var input = require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>a);
|
||||||
|
var moves = input.map(line=>(line.split(" "))).map(a=>([a[1], a[7]]));
|
||||||
|
|
||||||
|
var statesObj = {};
|
||||||
|
for(var state of moves.map(a=>(a[0])).concat(moves.map(a=>(a[1])))){
|
||||||
|
statesObj[state] = 0;
|
||||||
|
}
|
||||||
|
var states = Object.keys(statesObj);
|
||||||
|
var visited = [];
|
||||||
|
|
||||||
|
while(visited.length < states.length){
|
||||||
|
var possibleMoves = states.filter(s=>(moves.filter(m=>(m[1]==s)).map(m=>(m[0])).filter(ms=>(visited.indexOf(ms) == -1)).length == 0)).filter(s=>(visited.indexOf(s) == -1)).sort();
|
||||||
|
var move = possibleMoves[0];
|
||||||
|
visited.push(move);
|
||||||
|
}
|
||||||
|
console.log(visited.join(""));
|
44
07/part2.js
Normal file
44
07/part2.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
var input = require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>a);
|
||||||
|
var moves = input.map(line=>(line.split(" "))).map(a=>([a[1], a[7]]));
|
||||||
|
|
||||||
|
var statesObj = {};
|
||||||
|
for(var state of moves.map(a=>(a[0])).concat(moves.map(a=>(a[1])))){
|
||||||
|
statesObj[state] = 0;
|
||||||
|
}
|
||||||
|
var states = Object.keys(statesObj);
|
||||||
|
var visited = [];
|
||||||
|
|
||||||
|
var workers = [
|
||||||
|
[0, ""],
|
||||||
|
[0, ""],
|
||||||
|
[0, ""],
|
||||||
|
[0, ""],
|
||||||
|
[0, ""],
|
||||||
|
]
|
||||||
|
|
||||||
|
var i = -1;
|
||||||
|
|
||||||
|
while(visited.length < states.length){
|
||||||
|
for(var worker of workers){
|
||||||
|
if(worker[0] == 0){
|
||||||
|
if(worker[1]){
|
||||||
|
visited.push(worker[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var possibleMoves = states.filter(s=>(moves.filter(m=>(m[1]==s)).map(m=>(m[0])).filter(ms=>(visited.indexOf(ms) == -1)).length == 0)).filter(s=>(visited.indexOf(s) == -1)).filter(s=>(workers.map(w=>(w[1])).indexOf(s) == -1)).sort();
|
||||||
|
for(var worker of workers){
|
||||||
|
if(worker[0] == 0){
|
||||||
|
worker[1] = possibleMoves.shift();
|
||||||
|
if(worker[1]){
|
||||||
|
worker[0] = worker[1].charCodeAt(0) - "A".charCodeAt(0);
|
||||||
|
worker[0] += 60;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
worker[0]--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
console.log(i);
|
Loading…
x
Reference in New Issue
Block a user