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.

Very easy today. Not going to optimize. I'm not going to do it.

with open('testinput', 'r') as f:

    for line in f:

        markerFound = False

        count = 0

        line = line.strip()

        curFound = ''

        for ch in line:

            curFound += ch

            if count >= 13 and not markerFound:

                good = True

                for c in curFound:

                    if curFound.count(c) > 1:

                        good=False

                if not good:

                    curFound = curFound[1:]

                if good: 

                    markerFound = True

                    break

            count += 1

        print('Line Count:', count + 1)
Jump in the discussion.

No email address required.

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