From fe75912ce11460514afbe32cc4e226dbcbde3e8e Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Mon, 5 Dec 2022 16:28:03 +1030 Subject: [PATCH] 2022 Day5 Python (cleaned) --- 2022/day5.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 2022/day5.py diff --git a/2022/day5.py b/2022/day5.py new file mode 100644 index 0000000..7fe157d --- /dev/null +++ b/2022/day5.py @@ -0,0 +1,22 @@ +import re +numbers_pattern = re.compile(r'((?:(? 0} +order_numbers = [[int(x) for x in numbers_pattern.findall(line)] for line in input_orders.split('\n')] + +stacks = {k:[c for c in v] for k,v in starting_stack_strings.items()} +for (num, source, dest) in order_numbers: + for i in range(0, num): + stacks[dest].append(stacks[source].pop()) +print('Part 1: ' + ''.join(s[-1] for s in stacks.values())) + +stacks = {k:[c for c in v] for k,v in starting_stack_strings.items()} +for (num, source, dest) in order_numbers: + stacks[dest] += stacks[source][-num:] + stacks[source] = stacks[source][:-num] +print('Part 2: ' + ''.join(s[-1] for s in stacks.values()))