File tree Expand file tree Collapse file tree 2 files changed +44
-5
lines changed
Expand file tree Collapse file tree 2 files changed +44
-5
lines changed Original file line number Diff line number Diff line change 22from pprint import pprint
33
44
5- # TODO https://github.com/PodolskiBartosz/advent-of-code-2022/blob/main/day-8/main.py
6-
75test = """30373
8625512
9765332
Original file line number Diff line number Diff line change 1- # --- Day 1: ---
1+ # --- Day 1: Secret Entrance ---
2+
23
34def 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
725def 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
1152if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments