Compare commits
2 Commits
47606c7dbf
...
3700b24968
| Author | SHA1 | Date | |
|---|---|---|---|
| 3700b24968 | |||
| 874453fc1d |
40
day-02/day-02.py
Normal file
40
day-02/day-02.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
def part_1(input):
|
||||||
|
h_pos = 0
|
||||||
|
depth = 0
|
||||||
|
for line in input:
|
||||||
|
step = line.split()
|
||||||
|
if 'forward' == step[0]:
|
||||||
|
h_pos += int(step[1])
|
||||||
|
elif 'up' == step[0]:
|
||||||
|
depth -= int(step[1])
|
||||||
|
elif 'down' == step[0]:
|
||||||
|
depth += int(step[1])
|
||||||
|
result = h_pos * depth
|
||||||
|
print("Part 1 result:", result)
|
||||||
|
|
||||||
|
|
||||||
|
def part_2(input):
|
||||||
|
h_pos = 0
|
||||||
|
depth = 0
|
||||||
|
aim = 0
|
||||||
|
for line in input:
|
||||||
|
step = line.split()
|
||||||
|
if 'forward' == step[0]:
|
||||||
|
h_pos += int(step[1])
|
||||||
|
depth += aim * int(step[1])
|
||||||
|
elif 'up' == step[0]:
|
||||||
|
aim -= int(step[1])
|
||||||
|
elif 'down' == step[0]:
|
||||||
|
aim += int(step[1])
|
||||||
|
result = h_pos * depth
|
||||||
|
print("Part 2 result:", result)
|
||||||
|
|
||||||
|
|
||||||
|
input = list()
|
||||||
|
with open('input.txt') as fp:
|
||||||
|
input = fp.readlines()
|
||||||
|
|
||||||
|
part_1(input)
|
||||||
|
part_2(input)
|
||||||
1000
day-02/input.txt
Normal file
1000
day-02/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,7 @@ def part_2(input):
|
|||||||
result = 0
|
result = 0
|
||||||
for line in input:
|
for line in input:
|
||||||
pass
|
pass
|
||||||
print("Part 1 result:", result)
|
print("Part 2 result:", result)
|
||||||
|
|
||||||
|
|
||||||
input = list()
|
input = list()
|
||||||
|
|||||||
Reference in New Issue
Block a user