[2022] Day6 added
This commit is contained in:
parent
a496112b25
commit
596c74d0d0
|
@ -10,6 +10,7 @@ class Program
|
|||
new Day2();
|
||||
new Day3();
|
||||
new Day4();
|
||||
new Day6();
|
||||
new Day7();
|
||||
}
|
||||
}
|
|
@ -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)
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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)
|
Loading…
Reference in New Issue