Added day 2.

This commit is contained in:
David Vereb 2021-12-06 14:56:21 -05:00
parent 61a451058a
commit c426ab7008
3 changed files with 1037 additions and 0 deletions

1000
2021/2/data Normal file

File diff suppressed because it is too large Load Diff

17
2021/2/main.py Normal file
View File

@ -0,0 +1,17 @@
x = 0 # horizontal position
d = 0 # depth
with open('data', 'r') as fp:
for line in fp:
data = line.split()
if(data[0] == 'forward'):
x = x + int(data[1])
elif(data[0] == 'down'):
d = d + int(data[1])
else:
d = d - int(data[1])
print "x: ", x
print "d: ", d
print " : ", x * d

20
2021/2/main2.py Normal file
View File

@ -0,0 +1,20 @@
aim = 0
x = 0 # horizontal position
d = 0 # depth
with open('data', 'r') as fp:
for line in fp:
data = line.split()
if(data[0] == 'forward'):
x = x + int(data[1])
d = d + aim * int(data[1])
elif(data[0] == 'down'):
aim = aim + int(data[1])
else:
aim = aim - int(data[1])
print " x: ", x
print " d: ", d
print "aim: ", aim
print " : ", x * d