advent-of-code

advent of code (partial solutions)
Log | Files | Refs | README

commit 8eb698e5e2e6a0b9023c47087483b2521980bafa
parent a8e04591448fe9622d59224e1b88e395520905dd
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed,  1 Dec 2021 21:14:47 -0800

Add day 2: python

Diffstat:
A2021/aoc02.py | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/2021/aoc02.py b/2021/aoc02.py @@ -0,0 +1,24 @@ +import sys + +lines = sys.stdin.read().split("\n") +x = 0 +d1 = 0 # depth +d2 = 0 # depth +aim = 0 +for line in lines: + if line == "": + break + d, _, count = line.partition(" ") + count = int(count) + if d == "up": + d1 -= count + aim -= count + if d == "forward": + x += count + d2 += aim * count + if d == "down": + d1 += count + aim += count +print(x * d1) +print(x * d2) +