Added day 2.
This commit is contained in:
parent
61a451058a
commit
c426ab7008
1000
2021/2/data
Normal file
1000
2021/2/data
Normal file
File diff suppressed because it is too large
Load Diff
17
2021/2/main.py
Normal file
17
2021/2/main.py
Normal 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
20
2021/2/main2.py
Normal 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
|
Loading…
Reference in New Issue
Block a user