More solutions

This commit is contained in:
Jed
2021-12-02 10:36:43 -05:00
parent 10164b32f9
commit 3ebbc0655b
11 changed files with 1260 additions and 0 deletions

33
2021/02.py Normal file
View File

@@ -0,0 +1,33 @@
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)