Day 2
This commit is contained in:
34
02.py
Normal file
34
02.py
Normal 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
7
02.test
Normal file
@@ -0,0 +1,7 @@
|
||||
direction amount
|
||||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
||||
Reference in New Issue
Block a user