Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_puzzle_input(a_file_name: str) -> list[list[int]]:
- with open(a_file_name) as INFILE:
- return [[int(x) for x in line.split()] for line in INFILE if not line.startswith('#')]
- def solve_p1(a_num_list: list[list[int]]) -> int:
- return sum([max(line) - min(line) for line in a_num_list])
- def p2_line_value(a_num_list: list[int]) -> int:
- for i in range(len(a_num_list)):
- for j in range(len(a_num_list)):
- if i == j:
- continue
- i_num = a_num_list[i]
- j_num = a_num_list[j]
- if i_num / j_num == i_num // j_num:
- return max(i_num, j_num) // min (i_num, j_num)
- def solve_p2(a_num_list: list[list[int]]) -> int:
- return sum([p2_line_value(line) for line in a_num_list])
- spreadsheet = get_puzzle_input('advent_of_code_2017_day_02.txt')
- # print(f'{spreadsheet=}')
- print(f'{solve_p1(spreadsheet)=}')
- print(f'{solve_p2(spreadsheet)=}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement