Skip to content

Commit ab7f6dc

Browse files
committed
Add day-01
1 parent 6172afd commit ab7f6dc

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

2022/python/day-8/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from pprint import pprint
33

44

5-
# TODO https://github.com/PodolskiBartosz/advent-of-code-2022/blob/main/day-8/main.py
6-
75
test = """30373
86
25512
97
65332

2025/day-01/main.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
1-
# --- Day 1: ---
1+
# --- Day 1: Secret Entrance ---
2+
23

34
def part1():
4-
pass
5+
starting_pos = 50
6+
zero_count = 0
7+
# lines = open('example.txt').readlines()
8+
lines = open("input.txt", "r").readlines()
9+
10+
for line in lines:
11+
direction = line[0]
12+
distance = int(line[1:].strip())
13+
14+
if direction == "L":
15+
starting_pos = (starting_pos - distance) % 100
16+
else:
17+
starting_pos = (starting_pos + distance) % 100
18+
19+
if starting_pos == 0:
20+
zero_count += 1
21+
22+
print(f"Part 1: {zero_count}")
523

624

725
def part2():
8-
pass
26+
# lines = open('example.txt').readlines()
27+
lines = open("input.txt", "r").readlines()
28+
starting_pos = 50
29+
zero_count = 0
30+
31+
for line in lines:
32+
direction = line[0]
33+
distance = int(line[1:].strip())
34+
35+
if direction == "L":
36+
new_pos = (starting_pos - distance) % 100
37+
zero_count += distance // 100
38+
if starting_pos != 0 and (new_pos > starting_pos or new_pos == 0):
39+
zero_count += 1
40+
starting_pos = new_pos
41+
42+
else:
43+
new_pos = (starting_pos + distance) % 100
44+
zero_count += distance // 100
45+
if new_pos < starting_pos:
46+
zero_count += 1
47+
starting_pos = new_pos
48+
49+
print(f"Part 2: {zero_count}")
950

1051

1152
if __name__ == "__main__":

0 commit comments

Comments
 (0)