Advertisement
bob_f

advent_of_code_2017_day_01.py

Jan 8th, 2024
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1.  
  2. def get_puzzle_input(a_file_name: str) -> list[int]:
  3.     with open('advent_of_code_2017_day_01.txt') as INFILE:
  4.         return [int(x) for x in INFILE.readline().rstrip()]
  5.  
  6. def solve_p1(a_num_list: list[int]) -> int:
  7.     a_l = a_num_list.copy()
  8.     a_l.append(a_l[0])
  9.     b_l: list[int] = [a_l[x] for x in range(len(a_l) - 1) if a_l[x] == a_l[x + 1]]        
  10.     return sum(b_l)
  11.  
  12. def solve_p2(a_num_list: list[int]) -> int:
  13.     a_l = a_num_list.copy()
  14.     a_l.extend(a_l)
  15.     len_num_list = len(a_num_list)
  16.     offset: int = len_num_list // 2
  17.  
  18.     b_l: list[int] = [a_l[x] for x in range(len_num_list) if a_l[x] == a_l[x + offset]]        
  19.     return sum(b_l)
  20.  
  21. num_list = get_puzzle_input('advent_of_code_2017_day_01.txt')
  22.  
  23. print(f'{solve_p1(num_list)=}')
  24. print(f'{solve_p2(num_list)=}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement