Skip to content

Instantly share code, notes, and snippets.

@Solaxun
Created December 4, 2021 20:12
Show Gist options
  • Save Solaxun/2b607eae42e0295da396e6a686ac432a to your computer and use it in GitHub Desktop.
Save Solaxun/2b607eae42e0295da396e6a686ac432a to your computer and use it in GitHub Desktop.
AoC 2021: Python Day 2
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