[2022] Day6 added

This commit is contained in:
Tiago Garcia 2023-06-07 23:58:57 +01:00
parent a496112b25
commit 596c74d0d0
No known key found for this signature in database
GPG Key ID: F423E37A2415E160
4 changed files with 32 additions and 0 deletions

View File

@ -10,6 +10,7 @@ class Program
new Day2();
new Day3();
new Day4();
new Day6();
new Day7();
}
}

View File

@ -6,4 +6,6 @@
* [Day 1](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day1.cs)
* [Day 2](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day2.cs)
* [Day 3](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day3.cs)
* [Day 4](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day4.cs)
* [Day 6](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day6.cs)
* [Day 7](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day7.cs)

View File

@ -0,0 +1,27 @@
namespace AdventOfCode.Year2022;
public class Day6
{
private static readonly string _input = File.ReadAllText("inputs/day6.txt");
public Day6()
{
Console.WriteLine("Day6 Solution");
Console.WriteLine($"Part1 Result: {GetValidMarkerIndex(4)}");
Console.WriteLine($"Part2 Result: {GetValidMarkerIndex(14)}");
Console.WriteLine("\n=============================\n");
}
private static int? GetValidMarkerIndex(int size)
{
for (int i = 0; i < _input.Length-size; i++)
if (ValidateMarker(_input.Substring(i, size)))
return i + size;
return null;
}
private static bool ValidateMarker(string marker)
{
return !marker.Where((c1, i) => marker.Where((c2, j) => c1 == c2 && i != j).Any()).Any();
}
}

View File

@ -8,4 +8,6 @@
* [Day 1](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day1.cs)
* [Day 2](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day2.cs)
* [Day 3](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day3.cs)
* [Day 4](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day4.cs)
* [Day 6](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day6.cs)
* [Day 7](https://github.com/TiagoRG/AdventOfCode/tree/main/AdventOfCode/Year2022/Day7.cs)