Advertisement
bob_f

advent_of_code_2017_day_02.py

Jan 8th, 2024
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1.  
  2. def get_puzzle_input(a_file_name: str) -> list[list[int]]:
  3.     with open(a_file_name) as INFILE:
  4.         return [[int(x) for x in line.split()] for line in INFILE if not line.startswith('#')]
  5.  
  6. def solve_p1(a_num_list: list[list[int]]) -> int:
  7.     return sum([max(line) - min(line) for line in a_num_list])
  8.  
  9. def p2_line_value(a_num_list: list[int]) -> int:
  10.     for i in range(len(a_num_list)):
  11.         for j in range(len(a_num_list)):
  12.             if i == j:
  13.                 continue
  14.  
  15.             i_num = a_num_list[i]
  16.             j_num = a_num_list[j]
  17.  
  18.             if i_num / j_num == i_num // j_num:
  19.                 return max(i_num, j_num) // min (i_num, j_num)
  20.  
  21. def solve_p2(a_num_list: list[list[int]]) -> int:
  22.     return sum([p2_line_value(line) for line in a_num_list])
  23.  
  24. spreadsheet = get_puzzle_input('advent_of_code_2017_day_02.txt')
  25. # print(f'{spreadsheet=}')
  26.  
  27. print(f'{solve_p1(spreadsheet)=}')
  28. print(f'{solve_p2(spreadsheet)=}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement