Last active
December 5, 2022 22:21
-
-
Save dartharva/9fddb2086857efe60d14c16c92f5c541 to your computer and use it in GitHub Desktop.
Advent of Code 2022, Day 3 - Simple, verbose python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stacks = { | |
1: ['M','S','J','L','V','F','N','R'], | |
2: ['H','W','J','F','Z','D','N','P'], | |
3: ['G','D','C','R','W'], | |
4: ['S','B','N'], | |
5: ['N','F','B','C','P','W','Z','M'], | |
6: ['W','M','R','P'], | |
7: ['W','S','L','G','N','T','R'], | |
8: ['V','B','N','F','H','T','Q'], | |
9: ['F','N','Z','H','M','L'], | |
} | |
with open('input.txt', 'r') as file: #input.txt has been edited to show only steps | |
procedure = [[int(x) for x in y.split() if x.isdigit()] for y in file.read().split('\n')] | |
for step in procedure: | |
quant = step[0] | |
fromcrate = step[1] | |
tocrate = step[2] | |
crates_moved = [stacks[fromcrate].pop(0) for i in range(quant)] | |
#crates_moved.reverse() #for Part 1 | |
stacks[tocrate] = crates_moved + stacks[tocrate] | |
print(STACKS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment