From 5b87ed8692e7854fbc3d4529a920314f00330d68 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Wed, 11 Dec 2024 19:23:03 +0100 Subject: [PATCH] add 2022/day06 --- 2022/06/main.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 2022/06/main.py diff --git a/2022/06/main.py b/2022/06/main.py new file mode 100644 index 0000000..1fa13ec --- /dev/null +++ b/2022/06/main.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- encoding: utf-8; py-indent-offset: 4 -*- + +# Author: Sebastian Mark +# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de) + +# pylint: disable=missing-module-docstring,missing-function-docstring,consider-using-f-string + + +def readinput(): + with open("input", "r", encoding="utf-8") as file: + lines = file.read().strip() + return lines + + +def main(): + datastream = readinput() + + # part 1 + for i in range(len(datastream) - 4): + uniq = set(datastream[i : i + 4]) + if len(uniq) == 4: + print("Frist marker at %d" % (i + 4)) + break + + # part 2 + for i in range(len(datastream) - 14): + uniq = set(datastream[i : i + 14]) + if len(uniq) == 14: + print("Frist marker at %d" % (i + 14)) + break + + +if __name__ == "__main__": + main()