From bf613c4583fcc5e6f7b62426827d8e5f259f9761 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Wed, 7 Dec 2022 01:14:20 +0100 Subject: [PATCH] 6 --- 2022/06/README.md | 11 +++++++++++ 2022/06/python/main.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 2022/06/README.md create mode 100644 2022/06/python/main.py diff --git a/2022/06/README.md b/2022/06/README.md new file mode 100644 index 0000000..77534c9 --- /dev/null +++ b/2022/06/README.md @@ -0,0 +1,11 @@ +# 06 + +Mhh. Don't know why this was day 6. It was a 2 minute thing, a lot easier than the days before. + +
+ Solutions +
    +
  1. 1912
  2. +
  3. 2122
  4. +
+
diff --git a/2022/06/python/main.py b/2022/06/python/main.py new file mode 100644 index 0000000..36f58fb --- /dev/null +++ b/2022/06/python/main.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +from dataclasses import dataclass +from os.path import dirname, join + +# Day 06 + +# Common + + +def read_input(filename): + data = join(dirname(__file__), '..', filename) + with open(data) as f: + return f.read().strip() + + +test = read_input('test.txt') +data = read_input('input.txt') + + +def find_marker(buffer, size=4) -> int: + for i in range(len(buffer)): + subset = buffer[i:i+size] + if len(subset) == len(set(subset)): + return i + size + return -1 + + +# 1 +print('1.') +print(find_marker(test)) +print(find_marker(data)) + +# 2 +print('\n2.') +print(find_marker(test, size=14)) +print(find_marker(data, size=14))