From 7ba19b357918c1d6d5cf8387fc9ece1fd6c28a71 Mon Sep 17 00:00:00 2001 From: aaron Date: Tue, 6 Dec 2022 16:42:28 +0100 Subject: [PATCH] solve day 6 part 2 --- 6/tuningtrouble.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 6/tuningtrouble.py diff --git a/6/tuningtrouble.py b/6/tuningtrouble.py new file mode 100644 index 0000000..cb083d2 --- /dev/null +++ b/6/tuningtrouble.py @@ -0,0 +1,31 @@ +from itertools import count + +from aocd.models import Puzzle +from aocd import submit + + +def get_marker_pos(signal, N): + """ + iterate over input stream and find all the first occurence + where the Set from i to i+N equals N. This means there are + no duplicates within this particular range. + """ + for i in count(): + if len(set(signal[i : i + N])) == N: + return i + N + + +if __name__ == "__main__": + # get puzzle and parse data + puzzle = Puzzle(year=2022, day=6) + signal = puzzle.input_data + + # part a: + answer_a = get_marker_pos(signal, 4) + print(f"{answer_a}") + submit(answer_a, part="a", day=6, year=2022) + + # part b: + answer_b = get_marker_pos(signal, 14) + print(f"{answer_b}") + submit(answer_b, part="b", day=6, year=2022)