day2
This commit is contained in:
parent
5963532b35
commit
a77e5685bf
42
day2/day2.py
Normal file
42
day2/day2.py
Normal file
@ -0,0 +1,42 @@
|
||||
def part1(inp):
|
||||
horizontal_pos = 0
|
||||
depth = 0
|
||||
for line in inp:
|
||||
command, amount = line.split(" ")
|
||||
if command == "forward":
|
||||
horizontal_pos += int(amount)
|
||||
elif command == "up":
|
||||
depth -= int(amount)
|
||||
elif command == "down":
|
||||
depth += int(amount)
|
||||
#print(f"horizontal {horizontal_pos}, depth {depth}")
|
||||
print("Part 1", horizontal_pos * depth)
|
||||
|
||||
|
||||
def part2(inp):
|
||||
horizontal_pos = 0
|
||||
depth = 0
|
||||
aim = 0
|
||||
for line in inp:
|
||||
command, amount = line.split(" ")
|
||||
if command == "forward":
|
||||
horizontal_pos += int(amount)
|
||||
# It increases your depth by your aim multiplied by X.
|
||||
depth += aim * int(amount)
|
||||
elif command == "up":
|
||||
aim -= int(amount)
|
||||
elif command == "down":
|
||||
aim += int(amount)
|
||||
#print(f"horizontal {horizontal_pos}, depth {depth}")
|
||||
print("Part 2", horizontal_pos * depth)
|
||||
|
||||
|
||||
def main(input_file):
|
||||
with open(input_file) as f:
|
||||
entries = f.readlines()
|
||||
part1(entries)
|
||||
part2(entries)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main("input.txt")
|
1000
day2/input.txt
Normal file
1000
day2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user