refactor ParseRules into separate function for part 2

This commit is contained in:
Colin McMillen 2020-12-07 14:40:23 -05:00
parent c951980f73
commit 217a59affb

View File

@ -40,10 +40,13 @@ namespace AdventOfCode {
} }
} }
static int ParseRules(string[] rules) { static List<Contains> ParseRules(string[] rules) {
var contains = new List<Contains>(); var contains = new List<Contains>();
rules.ToList().ForEach(rule => AddRules(rule, contains)); rules.ToList().ForEach(rule => AddRules(rule, contains));
return contains;
}
static int ComputePart1(List<Contains> contains) {
int setSize = 0; int setSize = 0;
var result = new HashSet<string>(); var result = new HashSet<string>();
result.Add("shiny gold"); result.Add("shiny gold");
@ -62,11 +65,12 @@ namespace AdventOfCode {
} }
static int Part1() { static int Part1() {
string[] input = File.ReadAllLines(Util.RootDir + "day07.txt"); List<Contains> contains = ParseRules(File.ReadAllLines(Util.RootDir + "day07.txt"));
return ParseRules(input); return ComputePart1(contains);
} }
static int Part2() { static int Part2() {
List<Contains> contains = ParseRules(File.ReadAllLines(Util.RootDir + "day07.txt"));
return -1; 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. faded blue bags contain no other bags.
dotted black bags contain no other bags.".Split('\n'); 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(213, Part1());
Assert.Equal(-1, Part2()); Assert.Equal(-1, Part2());