Skip to content

Commit

Permalink
Solve day 1 part 1 (and lint...)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjalkio committed Dec 2, 2023
1 parent a2cc983 commit 9b7c96f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def read_puzzle_input(file_name="puzzle_input.txt"):
puzzle_input_file_contents = f.read()

# Sublime always adds a trailing newline, let's remove that
puzzle_input = puzzle_input_file_contents[:-1]
return puzzle_input
if puzzle_input_file_contents[-1] == "\n":
puzzle_input_file_contents = puzzle_input_file_contents[:-1]
return puzzle_input_file_contents


def setup_day(year=""):
Expand Down
4 changes: 2 additions & 2 deletions year_2020/day11/seating_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _get_num_occupied_seats(seat_layout):

def _get_surrounding_chairs(seat_layout):
surrounding_chairs = defaultdict(list)
for (i, j) in seat_layout.keys():
for i, j in seat_layout.keys():
for ii in range(i - 1, i + 2):
for jj in range(j - 1, j + 2):
if ii == i and jj == j:
Expand All @@ -41,7 +41,7 @@ def get_surrounding_chairs_part_2(seat_layout):
if i != 0 or j != 0:
directions.append((i, j))

for (x, y) in seat_layout.keys():
for x, y in seat_layout.keys():
for dx, dy in directions:
possible_surrounding_x = x + dx
possible_surrounding_y = y + dy
Expand Down
2 changes: 1 addition & 1 deletion year_2021/day15/chiton.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_lowest_risk_path_risk(puzzle_input, use_full_map=False):
x = current_node.x
y = current_node.y
neighbors = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
for (x, y) in neighbors:
for x, y in neighbors:
if (x, y) not in risk_map:
continue
risk_to = current_node.lowest_risk_to + risk_map[(x, y)]
Expand Down
4 changes: 2 additions & 2 deletions year_2021/day25/sea_cucumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_num_steps_no_movement(puzzle_input):
if ((x + 1) % x_wrap, y) not in locations:
east_movers.add((x, y))

for (x, y) in east_movers:
for x, y in east_movers:
del locations[(x, y)]
locations[((x + 1) % x_wrap, y)] = EAST

Expand All @@ -36,7 +36,7 @@ def get_num_steps_no_movement(puzzle_input):
if (x, (y + 1) % y_wrap) not in locations:
south_movers.add((x, y))

for (x, y) in south_movers:
for x, y in south_movers:
del locations[(x, y)]
locations[(x, (y + 1) % y_wrap)] = SOUTH

Expand Down
2 changes: 1 addition & 1 deletion year_2022/day12/hill_climbing_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _bfs(heightmap, starting_pos, best_signal_pos):
(curr_x, curr_y + 1),
(curr_x, curr_y - 1),
]
for (x, y) in neighbors:
for x, y in neighbors:
if (
(x, y) not in heightmap
or (x, y) in visited
Expand Down
2 changes: 1 addition & 1 deletion year_2022/day24/blizzard_basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _move(grid):
max_y = max(y for x, y in grid) - 1

new_grid = defaultdict(str)
for (x, y) in grid:
for x, y in grid:
if grid[x, y] == WALL:
new_grid[x, y] = WALL
continue
Expand Down
6 changes: 5 additions & 1 deletion year_2023/day01/trebuchet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@


def sum_calibration_values(puzzle_input):
return 0
answer = 0
for value in puzzle_input.split("\n"):
digits = [c for c in value if c.isdigit()]
answer += int(digits[0] + digits[-1])
return answer


if __name__ == "__main__":
Expand Down

0 comments on commit 9b7c96f

Please sign in to comment.