Skip to content

Commit

Permalink
Added day 5 solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
CarbonHeartDev committed Dec 5, 2022
1 parent 7bc9c93 commit b077bc6
Show file tree
Hide file tree
Showing 2 changed files with 544 additions and 0 deletions.
33 changes: 33 additions & 0 deletions d5/crate_simulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def parse_crate_layout(file):
lines = []
lines.append(FILE.readline())
while(lines[len(lines) - 1] != " 1 2 3 4 5 6 7 8 9 \n"):
lines.append(FILE.readline())
lines.pop()
lines.reverse()

crate_layout = [[] for i in range(9)]
for line in lines:
for i in range(9):
char = line[i * 4 + 1]
if char != ' ':
crate_layout[i].append(char)

return crate_layout

def simulate_crate_mover_9000(crate_layout, file):
for line in FILE:
n,form_crate,to_crate = line.rstrip().replace("move ","").replace(" from ",",").replace(" to ",",").split(',')
for i in range(int(n)):
crate_layout[int(to_crate) - 1].append(crate_layout[int(form_crate) - 1].pop())

def simulate_crate_mover_9001(crate_layout, file):
for line in FILE:
n,form_crate,to_crate = line.rstrip().replace("move ","").replace(" from ",",").replace(" to ",",").split(',')
crate_layout[int(to_crate) - 1] = crate_layout[int(to_crate) - 1] + crate_layout[int(form_crate) - 1][-int(n):]
crate_layout[int(form_crate) - 1] = crate_layout[int(form_crate) - 1][:-int(n)]
FILE = open("downloadedInput.txt")

#crate_rows = parse_crate_layout(FILE)
#FILE.readline()
#simulate_crate_mover_9001(crate_rows, FILE)
Loading

0 comments on commit b077bc6

Please sign in to comment.