Advertisement
bob_f

aoc_2023_day_21.py

Jan 4th, 2024 (edited)
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1.  
  2. import pprint
  3.  
  4. def get_puzzle_input(a_file_name: str) -> list[list[str]]:
  5.     with open(a_file_name) as INFILE:
  6.         return [[x for x in line.rstrip()] for line in INFILE if not line.startswith('!')]
  7.  
  8.  
  9. def get_grid(a_puzzle_input: list[list[str]]) -> list[list[str]]:
  10.     return \
  11.         [['#'] + (['#'] * len(a_puzzle_input[0])) + ['#']] + \
  12.         [['#'] + line + ['#'] for line in a_puzzle_input] + \
  13.         [['#'] + (['#'] * len(a_puzzle_input[0])) + ['#']]
  14.  
  15.    
  16. def get_start(a_grid: list[list[str]]) -> tuple[int, int]:
  17.  
  18.     for row in range(len(grid)):
  19.         for col in range(len(grid[0])):
  20.             if grid[row][col] == 'S':
  21.                 return row, col
  22.            
  23.     assert False, 'How did I get here?'
  24.  
  25.     return -1, -1
  26.  
  27.  
  28. puzzle_input = get_puzzle_input('advent_of_code_2023_day_21.txt')
  29. grid = get_grid(puzzle_input)
  30. pprint.pprint(grid)
  31.  
  32. row, col = get_start(grid)
  33. print(f'{row}, {col}')
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement