day 7 done
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
with open(r'2022\day_5\input.txt', 'r') as file:
|
||||
with open(r'advent_of_code\2022\day_5\input.txt', 'r') as file:
|
||||
input = file.read()
|
||||
with open(r'advent_of_code\2022\day_5\test_input.txt', 'r') as file:
|
||||
test_input = file.read()
|
||||
|
||||
# print(input)
|
||||
|
||||
@@ -14,17 +16,8 @@ pile_map = {
|
||||
8: 29,
|
||||
9: 33
|
||||
}
|
||||
test_input = ''' [D]
|
||||
[N] [C]
|
||||
[Z] [M] [P]
|
||||
1 2 3
|
||||
|
||||
move 1 from 2 to 1
|
||||
move 3 from 1 to 3
|
||||
move 2 from 2 to 1
|
||||
move 1 from 1 to 2'''
|
||||
|
||||
# input = test_input
|
||||
input = test_input
|
||||
|
||||
line_first_move = input.find('move')
|
||||
loading_area = input[:(line_first_move-2)]
|
||||
@@ -54,8 +47,8 @@ def add_to_pile(value, pile_number, loading_area):
|
||||
loading_area = '\n'.join(''.join(line) for line in lines)
|
||||
return loading_area
|
||||
|
||||
test = add_to_pile('X',3, loading_area)
|
||||
print(test)
|
||||
# test = add_to_pile('X',3, loading_area)
|
||||
# print(test)
|
||||
|
||||
def move_box(from_pile, to_pile):
|
||||
# find the box on the top of the pile
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
|
||||
def main():
|
||||
print("Advent of Code - Day 5")
|
||||
file_task_1 = open(r'advent_of_code\2022\day_5\input.txt', 'r')
|
||||
file_task_1 = open(r'advent_of_code\2022\day_5\test_input.txt', 'r')
|
||||
file_task_2 = open(r'advent_of_code\2022\day_5\input.txt', 'r')
|
||||
task_1(file_task_1)
|
||||
task_2(file_task_2)
|
||||
#task_2(file_task_2)
|
||||
|
||||
|
||||
def get_sections(file):
|
||||
@@ -34,10 +34,13 @@ def get_sections(file):
|
||||
def task_1(file):
|
||||
# Iterate over instructions, get relevant values from it and move the creates
|
||||
instructions, levels, stacks = get_sections(file)
|
||||
#print(stacks)
|
||||
for instruction in instructions:
|
||||
quantity, from_stack_order, to_stack_order = [int(i) for i in instruction.split(" ") if i.isnumeric()]
|
||||
while quantity != 0:
|
||||
print(stacks)
|
||||
stacks[to_stack_order-1].append(stacks[from_stack_order - 1].pop()) # Move crates each after another
|
||||
print(stacks)
|
||||
quantity -= 1
|
||||
print("Task 1 result: ", end="")
|
||||
[print(stack[-1], end="") for stack in stacks]
|
||||
|
||||
Reference in New Issue
Block a user