This commit is contained in:
Jed
2021-12-02 00:14:44 -05:00
parent e0dacc33b0
commit 9ebb47bec3
3 changed files with 1042 additions and 0 deletions

34
02.py Normal file
View File

@@ -0,0 +1,34 @@
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, aim)
print(x, y, x*y)

7
02.test Normal file
View File

@@ -0,0 +1,7 @@
direction amount
forward 5
down 5
forward 8
up 3
down 8
forward 2

1001
02.txt Normal file

File diff suppressed because it is too large Load Diff