part 1 solved of day 2

This commit is contained in:
Paul Maier 2021-12-13 18:13:34 +01:00
parent 884299765b
commit b55fdbe333
3 changed files with 1039 additions and 0 deletions

1000
Day02/data/input.txt Normal file

File diff suppressed because it is too large Load Diff

6
Day02/data/test.txt Normal file
View File

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2

33
Day02/day02.py Normal file
View File

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