Skip to content

Commit 267f057

Browse files
committed
add solution for 2021/02
1 parent 46fad0a commit 267f057

File tree

6 files changed

+1031
-5
lines changed

6 files changed

+1031
-5
lines changed

2020/test.py

-3
This file was deleted.

2021/01_puzzle1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
with open("01_puzzle_input.txt", "r") as file:
1+
with open("2021/01_puzzle_input.txt", "r") as file:
22
content = file.readlines()
33

44
increased = 0

2021/01_puzzle2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
with open("01_puzzle_input.txt", "r") as file:
1+
with open("2021/01_puzzle_input.txt", "r") as file:
22
content = file.readlines()
33

44
increased = 0

2021/02_puzzle1.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
content = open("2021/02_puzzle_input.txt", "r").read().splitlines()
2+
3+
depth = 0
4+
horizontal = 0
5+
6+
for line in content:
7+
if line.startswith("forward "):
8+
horizontal += int(line.split(" ")[1])
9+
elif line.startswith("down "):
10+
depth += int(line.split(" ")[1])
11+
elif line.startswith("up "):
12+
depth -= int(line.split(" ")[1])
13+
print(horizontal * depth)

2021/02_puzzle2.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
content = open("2021/02_puzzle_input.txt", "r").read().splitlines()
2+
3+
depth = 0
4+
horizontal = 0
5+
aim = 0
6+
7+
for line in content:
8+
if line.startswith("forward "):
9+
value = int(line.split(" ")[1])
10+
horizontal += value
11+
depth += aim * value
12+
elif line.startswith("down "):
13+
aim += int(line.split(" ")[1])
14+
elif line.startswith("up "):
15+
aim -= int(line.split(" ")[1])
16+
print(horizontal * depth)

0 commit comments

Comments
 (0)