This commit is contained in:
Thibaud Gasser 2021-12-02 13:39:56 +01:00
parent 5963532b35
commit a77e5685bf
2 changed files with 1042 additions and 0 deletions

42
day2/day2.py Normal file
View 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

File diff suppressed because it is too large Load Diff