From f9ace9f63d12205b51bfcea3178a2c3471d6cd3a Mon Sep 17 00:00:00 2001 From: Mika Suhonen Date: Tue, 6 Dec 2022 07:31:45 +0200 Subject: [PATCH] Do both in one go and bit of clean up --- 06/f.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/06/f.py b/06/f.py index 39d35ed..c075e3f 100644 --- a/06/f.py +++ b/06/f.py @@ -3,17 +3,22 @@ import os input = open(os.path.dirname(__file__) + "/input.txt", "r").read() -index = 0 -index2 = 0 +index, index1, index2 = 0, 0, 0 buf = [] + for x in input: index += 1 - index2 += 1 buf.append(x) - if len(buf) == 14: - if len(set(buf)) == 14: - break - else: - buf.pop(0) + if index1 == 0 and len(buf) == 4: + if len(set(buf)) == 4: + index1 = index + buf.pop(0) -print(index) + if index2 == 0 and len(buf) == 14: + if len(set(buf)) == 14: + index2 = index + break + buf.pop(0) + +print("First answer: " + str(index1)) +print("Second answer: " + str(index2))