Compare commits

..

No commits in common. "2ed395e1f3c255e0d19d037a50f2bac2426acb82" and "d4f34eb07c1e0197c9049aa4728386c67b9d3756" have entirely different histories.

3 changed files with 1 additions and 1051 deletions

View File

@ -63,58 +63,8 @@ namespace AdventOfCode {
Assert.Equal(140379120, Day1Part2(testInput)); Assert.Equal(140379120, Day1Part2(testInput));
} }
static bool IsPasswordValid1(string spec) {
string[] tokens = spec.Split(' ');
string[] numbers = tokens[0].Split('-');
int min = int.Parse(numbers[0]);
int max = int.Parse(numbers[1]);
char required = tokens[1][0];
string password = tokens[2];
int count = 0;
for (int i = 0; i < password.Length; i++) {
if (password[i] == required) {
count++;
}
}
return min <= count && count <= max;
}
static bool IsPasswordValid2(string spec) {
string[] tokens = spec.Split(' ');
string[] numbers = tokens[0].Split('-');
int lowIndex = int.Parse(numbers[0]) - 1;
int highIndex = int.Parse(numbers[1]) - 1;
char required = tokens[1][0];
string password = tokens[2];
return
(password[lowIndex] == required && password[highIndex] != required) ||
(password[lowIndex] != required && password[highIndex] == required);
}
static int Day2Part1() {
return File.ReadAllLines(RootDir + "day02.txt").Count(IsPasswordValid1);
}
static int Day2Part2() {
return File.ReadAllLines(RootDir + "day02.txt").Count(IsPasswordValid2);
}
[Fact]
static void Day2Test() {
Assert.True(IsPasswordValid1("1-3 a: abcde"));
Assert.False(IsPasswordValid1("1-3 b: cdefg"));
Assert.True(IsPasswordValid1("2-9 c: ccccccccc"));
Assert.Equal(603, Day2Part1());
Assert.True(IsPasswordValid2("1-3 a: abcde"));
Assert.False(IsPasswordValid2("1-3 b: cdefg"));
Assert.False(IsPasswordValid2("2-9 c: ccccccccc"));
Assert.Equal(404, Day2Part2());
}
static void Main(string[] args) { static void Main(string[] args) {
Day2Test(); Day1Test();
} }
} }
} }

File diff suppressed because it is too large Load Diff