import os def main(): #Starting value. current_point = 50 part_one_zeroes = 0 part_two_zeroes = 0 #Read file into content variable, split by endline characters. base_dir = os.path.dirname(__file__) file_path = os.path.join(base_dir, "input.txt") with open(file_path, 'r') as f: content = f.read().split('\n') #For each line in our input text, turn the dial. for x in content: current_point = part_one(x, current_point) if current_point == 0: part_one_zeroes += 1 print("Part 1 Answer: " + str(part_one_zeroes)) current_point = 50 for x in content: current_point, hits = part_two(x, current_point) part_two_zeroes += hits print("Part 1 Answer: " + str(part_two_zeroes)) def part_one(turn_input, current_point): direction = turn_input[0] amount = int(turn_input[1:]) if direction == 'L': current_point = (current_point - amount) % 100 if direction == 'R': current_point = (current_point + amount) % 100 return current_point def part_two(turn_input, current_point): direction = turn_input[0] amount = int(turn_input[1:]) zero_hits = 0 for _ in range(amount): if direction == 'L': current_point = (current_point - 1) % 100 if direction == 'R': current_point = (current_point + 1) % 100 if current_point == 0: zero_hits += 1 return current_point, zero_hits if __name__ == "__main__": main()