import sys from typing import List DIAL_START = 50 POSITIVE = 1 dial = [0] * 100 def parseString(filename: str) -> List[str]: with open(filename, 'r') as file: file_content = file.read() return file_content.strip().splitlines() def do_move(move: str, position: int, count: int) -> tuple[int, int]: # takes in string adjustment = int(move[1:]) if move[0] == 'L': # turn left distance = position if position != 0 else 100# to top of dial position -= adjustment else: # turn right distance = 100-position position += adjustment zero_hits = 0 if adjustment >= distance: extra = adjustment - distance zero_hits = 1 + (extra // 100) final_pos = position % 100 if final_pos == 0 and zero_hits > 0: zero_hits -= 1 count += zero_hits dial[final_pos] += 1 # landing on a number return (final_pos, count) def main() -> int: instructions = parseString(sys.argv[1]) position = DIAL_START count = 0 for i in instructions: position, count = do_move(i, position, count) return count + dial[position] if __name__ == "__main__": print(main())