-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay06.cs
61 lines (51 loc) · 1.59 KB
/
Day06.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
namespace AdventOfCode2022;
internal class Day06
{
private readonly string _input;
public Day06(string input)
{
_input = input;
}
public int PartOne() => FindMarker(4);
public int PartTwo() => FindMarker(14);
private int FindMarker(int markerSize)
{
for (var i = markerSize - 1; i < _input.Length; i++)
{
if (_input.Substring(i - (markerSize - 1), markerSize).ToHashSet().Count == markerSize)
{
return i + 1;
}
}
return -1;
}
}
public class Day06Test
{
private const string InputFile = "Day06.Input.txt";
[Theory]
[InlineData("mjqjpqmgbljsphdztnvjfqwrcgsmlb", 7)]
[InlineData("bvwbjplbgvbhsrlpgdmjqwftvncz", 5)]
[InlineData("nppdvjthqldpwncqszvftbrmjlhg", 6)]
[InlineData("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg", 10)]
[InlineData("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw", 11)]
[FileData(InputFile, 1282)]
public void TestPartOne(string input, int expected)
{
var solution = new Day06(input);
Assert.Equal(expected, solution.PartOne());
}
[Theory]
[InlineData("mjqjpqmgbljsphdztnvjfqwrcgsmlb", 19)]
[InlineData("bvwbjplbgvbhsrlpgdmjqwftvncz", 23)]
[InlineData("nppdvjthqldpwncqszvftbrmjlhg", 23)]
[InlineData("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg", 29)]
[InlineData("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw", 26)]
[FileData(InputFile, 3513)]
public void TestPartTwo(string input, int expected)
{
var solution = new Day06(input);
Assert.Equal(expected, solution.PartTwo());
}
}