Initial commit / Day 01 / Day 02
This commit is contained in:
1000
day02/input.txt
Normal file
1000
day02/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
17
day02/part1.py
Normal file
17
day02/part1.py
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
|
||||
hor = 0
|
||||
depth = 0
|
||||
for line in lines:
|
||||
cmd, strVal = line.split(" ")
|
||||
val = int(strVal)
|
||||
if cmd == 'forward':
|
||||
hor += val
|
||||
elif cmd == 'down':
|
||||
depth += val
|
||||
else:
|
||||
depth -= val
|
||||
|
||||
print(hor*depth)
|
||||
19
day02/part2.py
Normal file
19
day02/part2.py
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
|
||||
hor = 0
|
||||
depth = 0
|
||||
aim = 0
|
||||
for line in lines:
|
||||
cmd, strVal = line.split(" ")
|
||||
val = int(strVal)
|
||||
if cmd == 'forward':
|
||||
hor += val
|
||||
depth += aim * val
|
||||
elif cmd == 'down':
|
||||
aim += val
|
||||
else:
|
||||
aim -= val
|
||||
|
||||
print(hor*depth)
|
||||
Reference in New Issue
Block a user