-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay6.cs
46 lines (40 loc) · 1.1 KB
/
Day6.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
namespace advent_of_code_2022;
using System.Collections.Generic;
public class Day6
{
public static void Part1(string[] args)
{
string[] lines = File.ReadAllLines("day6-input.txt");
}
public static void Solve(string[] args)
{
string input = File.ReadAllText("day6-input.txt");
int firstIndex = 0;
HashSet<char> set = new HashSet<char>();
int result = 0;
for (var i = 0; i < input.Length; i++)
{
if (set.Count == 14)
{
result = i;
break;
}
char current = input[i];
if (!set.Add(current))
{
for (; firstIndex < i; firstIndex++)
{
char prevCh = input[firstIndex];
set.Remove(prevCh);
if (prevCh == current)
{
set.Add(current);
firstIndex++;
break;
}
}
}
}
Console.WriteLine(result);
}
}