Initial Commit

This commit is contained in:
Jose Caban
2025-11-30 20:28:10 -05:00
commit e9ac699e67
209 changed files with 39737 additions and 0 deletions

View File

@@ -0,0 +1,53 @@

string[] examples =
{
"mjqjpqmgbljsphdztnvjfqwrcgsmlb",
"bvwbjplbgvbhsrlpgdmjqwftvncz",
"nppdvjthqldpwncqszvftbrmjlhg",
"nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg",
"zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw",
};
int[] uniqueCount = { 4, 14 };
/**** Part 01 ***/
foreach (var unique in uniqueCount)
{
Console.WriteLine(String.Format("\nFinding based on {0} unique consequetive characters", unique));
// Perform ops on examples
foreach (string example in examples)
{
PrintFirstUniqueIndex(example, unique);
}
// Do it on the real puzzle
string fileName = "puzzle-input.txt";
using (StreamReader reader = File.OpenText(fileName))
{
string? line = reader.ReadLine();
if (line != null)
{
PrintFirstUniqueIndex(line, unique);
}
else
{
throw new InvalidDataException();
}
}
}
void PrintFirstUniqueIndex(string str, int uniqueLength)
{
for (int i = 0; i < str.Length; i++)
{
var substr = str.Substring(i, uniqueLength);
if (substr.Distinct().Count() == uniqueLength)
{
Console.WriteLine("Unique Index Start: " + (i+uniqueLength));
return;
}
}
throw new InvalidDataException();
}