Files
advent_of_code/2021/02.py
2021-12-02 10:36:43 -05:00

33 lines
896 B
Python

import pandas as pd
instruction_df = pd.read_csv('02.txt', sep=" ")
# instruction_df = pd.read_csv('02.test', sep=" ")
instruction_list = instruction_df.to_dict('records')
x = 0
y = 0
for one_instruction in instruction_list:
if one_instruction['direction'] == 'forward':
x += one_instruction['amount']
if one_instruction['direction'] == 'down':
y += one_instruction['amount']
if one_instruction['direction'] == 'up':
y -= one_instruction['amount']
print(x, y, x*y)
x = 0
y = 0
aim = 0
for one_instruction in instruction_list:
if one_instruction['direction'] == 'forward':
x += one_instruction['amount']
y += one_instruction['amount'] * aim
if one_instruction['direction'] == 'down':
aim += one_instruction['amount']
if one_instruction['direction'] == 'up':
aim -= one_instruction['amount']
print(x, y, x*y)