Unable to load image

Advent of Code day 6

was preparing my butthole after the last one but ended up being the fastest one i've done :marseyexcited:

with open("day6input.txt") as f:
    input = f.read()

# part 1

for i in range(len(input)):
    marker = set(input[i:i+4])
    if len(marker) == 4:
        answer = i + 4
        break

print(answer)

# part 2 

for i in range(len(input)):
    marker = set(input[i:i+14])
    if len(marker) == 14:
        answer = i + 14
        break

print(answer)
28
Jump in the discussion.

No email address required.

this was sort of easy

using static System.Linq.Enumerable;

namespace AOC2022.Puzzles;

public class Day6 : IPuzzle
{
	private readonly int _totalLength;
	private readonly string _actualInput;

	public Day6(IReadOnlyList<string> linesFromFile)
	{
		_actualInput = linesFromFile[0];
		_totalLength = _actualInput.Length;
	}

	public void SolveFirstPuzzle()
	{
		const int sopLength = 4;
		var result = Range(sopLength, _totalLength)
			.First(x => 
				_actualInput.Substring(x - sopLength, sopLength).ToHashSet().Count == sopLength);
		Console.WriteLine(result);
	}

	public void SolveSecondPuzzle()
	{
		const int somLength = 14;
		var result = Range(somLength, _totalLength)
			.First(x => 
				_actualInput.Substring(x - somLength, somLength).ToHashSet().Count == somLength);
		Console.WriteLine(result);
	}
}

can improve more but I got work today :( thx to rider for making it almost one line lmao

![](/images/16703170672943056.webp)

Jump in the discussion.

No email address required.



Now playing: In A Snow-Bound Land (DKC2).mp3

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.