rj1
about | log | files | refs
commit 8f5d4ba650fb8a6faafd0e2325cdb39bc7fe6d55
parent 438d4feff875cf28053b121f19882bbb7de8e92a
author: rj1 <[email protected]>
date:   Mon,  5 Dec 2022 11:38:46 -0600

day 5 solution

Diffstat:
A2022/05/solution.py | 42++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 2++
2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/2022/05/solution.py b/2022/05/solution.py @@ -0,0 +1,42 @@ +import os + +base_dir = os.path.realpath(os.path.dirname(__file__)) +with open(base_dir + "/input.txt", "r") as file: + input = file.read().rstrip() + +sections = input.split("\n\n") +# crates = sections[0] +moves = sections[1].split("\n") + +stacks = { + 1: ["N", "W", "B"], + 2: ["B", "M", "D", "T", "P", "S", "Z", "L"], + 3: ["R", "W", "Z", "H", "Q"], + 4: ["R", "Z", "J", "V", "D", "W"], + 5: ["B", "M", "H", "S"], + 6: ["B", "P", "V", "H", "J", "N", "G", "L"], + 7: ["S", "L", "D", "H", "F", "Z", "Q", "J"], + 8: ["B", "Q", "G", "J", "F", "S", "W"], + 9: ["J", "D", "C", "S", "M", "W", "Z"] +} + +for move in moves: + parts = move.split(" ") + num = int(parts[1]) + start = int(parts[3]) + end = int(parts[5]) + + # part 1 + # stacks[end] = stacks[start][:num][::-1] + stacks[end] + # stacks[start] = stacks[start][num:] + + # part 2 + stacks[end] = stacks[start][:num] + stacks[end] + stacks[start] = stacks[start][num:] + +order = "" +for i in range(1, 10): + if len(stacks[i]) > 0: + order += stacks[i][0] + +print(order) diff --git a/README.md b/README.md @@ -11,6 +11,7 @@ this repo contains my solutions for advent of code |2|00:13:22|4899|0| |3|00:04:22|368|0| |4|00:02:17|118|0| +|5|00:17:50|2168|0| ### part 2 @@ -20,6 +21,7 @@ this repo contains my solutions for advent of code |2|00:14:26|2281|0| |3|00:08:06|442|0| |4|00:05:06|443|0| +|5|12:38:15|61014|0| ## notes