AdventOfCode/Day02/day02.py

34 lines
619 B
Python

from pprint import pprint
def day02Part1():
with open("data/input.txt","r") as f:
myInput=f.read().splitlines()
newResult=convertData(myInput)
pprint(newResult)
horizontal=0
depth=0
for item in newResult:
if item[0]=="forward":
horizontal=horizontal+item[1]
if item[0]=="down":
depth=depth+item[1]
if item[0]=='up':
depth=depth-item[1]
print('Horizontal: ', horizontal, 'depth: ', depth, 'result: ', depth*horizontal)
def convertData(alist):
result=[]
for item in alist:
s=item.split()
s[1]=int(s[1])
result.append(s)
return result
if __name__ == '__main__':
day02Part1()