Created
December 4, 2021 20:12
-
-
Save Solaxun/2b607eae42e0295da396e6a686ac432a to your computer and use it in GitHub Desktop.
AoC 2021: Python Day 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = open('day2.txt').read().splitlines() | |
depth, horizontal = 0,0 | |
for line in data: | |
dir,amt = line.split() | |
amt = int(amt) | |
if dir == 'forward': | |
horizontal += amt | |
elif dir == 'down': | |
depth += amt | |
elif dir == 'up': | |
depth -= amt | |
print(depth * horizontal) | |
depth, horizontal, aim = 0,0,0 | |
for line in data: | |
dir,amt = line.split() | |
amt = int(amt) | |
if dir == 'forward': | |
horizontal += amt | |
depth = depth + aim * amt | |
elif dir == 'down': | |
aim += amt | |
elif dir == 'up': | |
aim -= amt | |
print(depth * horizontal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment