This repository has been archived on 2024-12-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
aoc2022/d6.py
2023-12-04 22:53:29 -05:00

42 lines
936 B
Python

import re
from string import ascii_lowercase, ascii_uppercase
EXAMPLE = """
mjqjpqmgbljsphdztnvjfqwrcgsmlb
"""
def clean(text: str) -> list[str]:
return list(filter(lambda l: l.strip() != "", text.splitlines()))
def solve(lines: list[str]):
line = lines[0]
for i in range(len(lines[0])):
l = line[i:i + 4]
if len(set(l)) == len(l):
return i + 4
# 2:55
def solve2(lines: list[str]):
line = lines[0]
for i in range(len(lines[0])):
l = line[i:i + 14]
if len(set(l)) == len(l):
return i + 14
# 3:50
def main():
example = clean(EXAMPLE)
print("Example 1:", solve(example))
data = clean(open("i6.txt").read())
print("Solution 1:", solve(data))
example = clean(EXAMPLE)
print("Example 2:", solve2(example))
data = clean(open("i6.txt").read())
print("Solution 2:", solve2(data))
if __name__ == "__main__":
main()