-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc04df5
commit 60ba5e9
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
Step B must be finished before step G can begin. | ||
Step G must be finished before step J can begin. | ||
Step J must be finished before step F can begin. | ||
Step U must be finished before step Z can begin. | ||
Step C must be finished before step M can begin. | ||
Step Y must be finished before step I can begin. | ||
Step Q must be finished before step A can begin. | ||
Step N must be finished before step L can begin. | ||
Step O must be finished before step A can begin. | ||
Step Z must be finished before step T can begin. | ||
Step I must be finished before step H can begin. | ||
Step L must be finished before step W can begin. | ||
Step F must be finished before step W can begin. | ||
Step T must be finished before step X can begin. | ||
Step A must be finished before step X can begin. | ||
Step K must be finished before step X can begin. | ||
Step S must be finished before step P can begin. | ||
Step M must be finished before step E can begin. | ||
Step E must be finished before step W can begin. | ||
Step D must be finished before step P can begin. | ||
Step P must be finished before step W can begin. | ||
Step X must be finished before step H can begin. | ||
Step V must be finished before step W can begin. | ||
Step R must be finished before step H can begin. | ||
Step H must be finished before step W can begin. | ||
Step N must be finished before step I can begin. | ||
Step X must be finished before step R can begin. | ||
Step D must be finished before step V can begin. | ||
Step V must be finished before step R can begin. | ||
Step F must be finished before step K can begin. | ||
Step P must be finished before step R can begin. | ||
Step P must be finished before step V can begin. | ||
Step S must be finished before step X can begin. | ||
Step I must be finished before step S can begin. | ||
Step J must be finished before step N can begin. | ||
Step T must be finished before step S can begin. | ||
Step T must be finished before step R can begin. | ||
Step K must be finished before step P can begin. | ||
Step N must be finished before step R can begin. | ||
Step G must be finished before step T can begin. | ||
Step I must be finished before step V can begin. | ||
Step G must be finished before step Q can begin. | ||
Step D must be finished before step H can begin. | ||
Step V must be finished before step H can begin. | ||
Step T must be finished before step K can begin. | ||
Step T must be finished before step W can begin. | ||
Step E must be finished before step H can begin. | ||
Step C must be finished before step R can begin. | ||
Step L must be finished before step K can begin. | ||
Step G must be finished before step Y can begin. | ||
Step Y must be finished before step O can begin. | ||
Step O must be finished before step E can begin. | ||
Step U must be finished before step S can begin. | ||
Step X must be finished before step W can begin. | ||
Step C must be finished before step D can begin. | ||
Step E must be finished before step P can begin. | ||
Step B must be finished before step R can begin. | ||
Step F must be finished before step R can begin. | ||
Step A must be finished before step D can begin. | ||
Step G must be finished before step M can begin. | ||
Step B must be finished before step Q can begin. | ||
Step Q must be finished before step V can begin. | ||
Step B must be finished before step W can begin. | ||
Step S must be finished before step H can begin. | ||
Step P must be finished before step X can begin. | ||
Step I must be finished before step M can begin. | ||
Step A must be finished before step S can begin. | ||
Step M must be finished before step X can begin. | ||
Step L must be finished before step S can begin. | ||
Step S must be finished before step W can begin. | ||
Step L must be finished before step V can begin. | ||
Step Z must be finished before step X can begin. | ||
Step M must be finished before step R can begin. | ||
Step T must be finished before step A can begin. | ||
Step N must be finished before step V can begin. | ||
Step M must be finished before step H can begin. | ||
Step E must be finished before step D can begin. | ||
Step F must be finished before step V can begin. | ||
Step B must be finished before step O can begin. | ||
Step G must be finished before step U can begin. | ||
Step J must be finished before step C can begin. | ||
Step G must be finished before step F can begin. | ||
Step Y must be finished before step M can begin. | ||
Step F must be finished before step D can begin. | ||
Step M must be finished before step P can begin. | ||
Step F must be finished before step T can begin. | ||
Step G must be finished before step A can begin. | ||
Step G must be finished before step Z can begin. | ||
Step K must be finished before step V can begin. | ||
Step J must be finished before step Z can begin. | ||
Step O must be finished before step Z can begin. | ||
Step B must be finished before step E can begin. | ||
Step Z must be finished before step V can begin. | ||
Step Q must be finished before step O can begin. | ||
Step J must be finished before step D can begin. | ||
Step Y must be finished before step E can begin. | ||
Step D must be finished before step R can begin. | ||
Step I must be finished before step F can begin. | ||
Step M must be finished before step V can begin. | ||
Step I must be finished before step D can begin. | ||
Step O must be finished before step P can begin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace AoC2018.Solutions.Day07 | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
public class Part01 : ISolution | ||
{ | ||
public string Solve(string input) | ||
{ | ||
(string Step, string PreRequisite)[] statements = input.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Select(this.ParseStatement).ToArray(); | ||
string[] allSteps = statements.Select(x => x.Step).Union(statements.Select(x => x.PreRequisite)).Distinct().ToArray(); | ||
var stepsWithDependencies = allSteps.ToDictionary(x => x, x => statements.Where(s => s.Step == x).Select(s => s.PreRequisite).ToArray()); | ||
|
||
var resolvedSteps = new List<string>(); | ||
|
||
while (resolvedSteps.Count != allSteps.Length) | ||
{ | ||
resolvedSteps.Add(this.GetNextAvailableStep(stepsWithDependencies, resolvedSteps)); | ||
} | ||
|
||
return string.Concat(resolvedSteps); | ||
} | ||
|
||
private string GetNextAvailableStep(Dictionary<string, string[]> stepsWithDependencies, List<string> resolvedSteps) | ||
{ | ||
return stepsWithDependencies.Where(x => !resolvedSteps.Contains(x.Key)).Where(x => x.Value.All(y => resolvedSteps.Contains(y))).Select(x => x.Key).OrderBy(x => x).First(); | ||
} | ||
|
||
private (string Step, string PreRequisite) ParseStatement(string statement) | ||
{ | ||
string[] components = statement.Split(' '); | ||
return (components[7], components[1]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters