diff --git a/day6/common.py b/day6/common.py new file mode 100644 index 0000000..d29b5a9 --- /dev/null +++ b/day6/common.py @@ -0,0 +1,3 @@ +def parse(filename: str): + with open(filename) as f: + return f.readline()[:-1] diff --git a/day6/part1.py b/day6/part1.py new file mode 100644 index 0000000..3e5b598 --- /dev/null +++ b/day6/part1.py @@ -0,0 +1,20 @@ +from common import parse + + +def all_different_characters(input: str) -> bool: + return all(map(lambda c: input.count(c) == 1, input)) + + +def solve(input: str) -> int: + i = 0 + while i < len(input) and not all_different_characters(input[i : i + 4]): + i += 1 + return i + 4 + + +def main(): + print(solve(parse("input"))) + + +if __name__ == "__main__": + main() diff --git a/day6/part2.py b/day6/part2.py new file mode 100644 index 0000000..83e8303 --- /dev/null +++ b/day6/part2.py @@ -0,0 +1,20 @@ +from common import parse + + +def all_different_characters(input: str) -> bool: + return all(map(lambda c: input.count(c) == 1, input)) + + +def solve(input: str) -> int: + i = 0 + while i < len(input) and not all_different_characters(input[i : i + 14]): + i += 1 + return i + 14 + + +def main(): + print(solve(parse("input"))) + + +if __name__ == "__main__": + main() diff --git a/template/part1.py b/template/part1.py old mode 100644 new mode 100755 index 305aecf..6692927 --- a/template/part1.py +++ b/template/part1.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python from common import parse