refactor ParseRules into separate function for part 2
This commit is contained in:
parent
c951980f73
commit
217a59affb
@ -40,10 +40,13 @@ namespace AdventOfCode {
|
||||
}
|
||||
}
|
||||
|
||||
static int ParseRules(string[] rules) {
|
||||
static List<Contains> ParseRules(string[] rules) {
|
||||
var contains = new List<Contains>();
|
||||
rules.ToList().ForEach(rule => AddRules(rule, contains));
|
||||
return contains;
|
||||
}
|
||||
|
||||
static int ComputePart1(List<Contains> contains) {
|
||||
int setSize = 0;
|
||||
var result = new HashSet<string>();
|
||||
result.Add("shiny gold");
|
||||
@ -62,11 +65,12 @@ namespace AdventOfCode {
|
||||
}
|
||||
|
||||
static int Part1() {
|
||||
string[] input = File.ReadAllLines(Util.RootDir + "day07.txt");
|
||||
return ParseRules(input);
|
||||
List<Contains> contains = ParseRules(File.ReadAllLines(Util.RootDir + "day07.txt"));
|
||||
return ComputePart1(contains);
|
||||
}
|
||||
|
||||
static int Part2() {
|
||||
List<Contains> contains = ParseRules(File.ReadAllLines(Util.RootDir + "day07.txt"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -83,7 +87,7 @@ vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
|
||||
faded blue bags contain no other bags.
|
||||
dotted black bags contain no other bags.".Split('\n');
|
||||
|
||||
Assert.Equal(4, ParseRules(example));
|
||||
Assert.Equal(4, ComputePart1(ParseRules(example)));
|
||||
|
||||
Assert.Equal(213, Part1());
|
||||
Assert.Equal(-1, Part2());
|
||||
|
Loading…
Reference in New Issue
Block a user