Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_puzzle_input(a_file_name: str) -> list[int]:
- with open('advent_of_code_2017_day_01.txt') as INFILE:
- return [int(x) for x in INFILE.readline().rstrip()]
- def solve_p1(a_num_list: list[int]) -> int:
- a_l = a_num_list.copy()
- a_l.append(a_l[0])
- b_l: list[int] = [a_l[x] for x in range(len(a_l) - 1) if a_l[x] == a_l[x + 1]]
- return sum(b_l)
- def solve_p2(a_num_list: list[int]) -> int:
- a_l = a_num_list.copy()
- a_l.extend(a_l)
- len_num_list = len(a_num_list)
- offset: int = len_num_list // 2
- b_l: list[int] = [a_l[x] for x in range(len_num_list) if a_l[x] == a_l[x + offset]]
- return sum(b_l)
- num_list = get_puzzle_input('advent_of_code_2017_day_01.txt')
- print(f'{solve_p1(num_list)=}')
- print(f'{solve_p2(num_list)=}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement