d6: python

master
pegasust 2022-12-06 05:11:35 +00:00
parent 053ca4fa25
commit 4d2c3161d2
2 changed files with 35 additions and 2 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env sh #!/usr/bin/env sh
echo "example" echo "example"
python3 ./src/d5.py ./data/example.txt python3 ./src/d6.py ./data/example.txt
echo "submission" echo "submission"
python3 ./src/d5.py ./data/submission.txt python3 ./src/d6.py ./data/submission.txt

View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
from typing import TextIO
def part1(f: TextIO):
s = f.read().strip()
print(f"{s=}")
for i in range(3, len(s)):
if len({c for c in s[i-3:i+1]}) == 4:
return i + 1
return None
def part2(f: TextIO):
s = f.read().strip()
print(f"{s=}")
for i in range(13, len(s)):
if len({c for c in s[i-13:i+1]}) == 14:
return i + 1
return None
def main(fileloc: str):
with open(fileloc, "r") as f:
print(f"{part1(f)=}")
with open(fileloc, "r") as f:
print(f"{part2(f)=}")
if __name__ == "__main__":
import sys
main(sys.argv[1])