-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay6.cs
More file actions
29 lines (25 loc) · 842 Bytes
/
Copy pathDay6.cs
File metadata and controls
29 lines (25 loc) · 842 Bytes
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
namespace Advent_of_Code_2022
{
internal class Day6 : ISolver
{
public string Title => "Tuning Trouble";
public string PartOne(string input) => GetStartOfMessageMarker(input, 4);
public string PartTwo(string input) => GetStartOfMessageMarker(input, 14);
private static string GetStartOfMessageMarker(string input, int lengthOfSequence)
{
for (int i = 0; i < input.Length; i++)
{
var last = i + lengthOfSequence;
if (last > input.Length)
{
last = input.Length;
}
if (input[i..last].Distinct().Count() == lengthOfSequence)
{
return last.ToString();
}
}
return "unknown";
}
}
}