from lib.aoclib import AOCLib from intcode_computer import IntcodeComputer puzzle = (2019, 5) # Initialise the helper library aoc = AOCLib(puzzle[0]) puzzle_input = aoc.get_puzzle_input(puzzle[1], AOCLib.to_list_int) diagnostic_code_1 = IntcodeComputer(puzzle_input, 1).run_to_end() aoc.print_solution(1, diagnostic_code_1) diagnostic_code_2 = IntcodeComputer(puzzle_input, 5).run_to_end() aoc.print_solution(2, diagnostic_code_2)
from lib.aoclib import AOCLib from lib.pixelgrid import PixelGrid puzzle = (2017, 21) # Initialise the helper library aoc = AOCLib(puzzle[0]) # Get the puzzle input puzzle_input = aoc.get_puzzle_input(puzzle[1], AOCLib.lines_to_list) # print(puzzle_input) pixel_grid = PixelGrid(puzzle_input) # Puzzle solution parts 1 and 2 iterations = 0 while iterations < 18: pixel_grid.expand_grid() iterations += 1 if iterations == 5: aoc.print_solution(1, pixel_grid.count_pixels()) aoc.print_solution(2, pixel_grid.count_pixels())
while number: ones += (number & 1) number >>= 1 return ones puzzle = (2017, 14) # Initialise the helper library aoc = AOCLib(puzzle[0]) # Get the puzzle input puzzle_input = aoc.get_puzzle_input(puzzle[1]) # print(puzzle_input) # Puzzle solution part 1 num_cols = 128 num_rows = 128 hash_inputs = ['{}-{}'.format(puzzle_input, row) for row in range(num_rows)] # Use a cache of part 1's answer as it takes a moderately # long time to calculate. hash_outputs = aoc.retrieve_some_data(puzzle[1], 'part1')
self.pointer = self.pointer[prev_or_next] def pop_tail(self): value = self.pointer[0] self.pointer[1][2] = self.pointer[2] self.pointer = self.pointer[2][1] = self.pointer[1] return value puzzle = (2018, 9) # Initialise the helper library aoc = AOCLib(puzzle[0]) puzzle_input = aoc.get_puzzle_input(puzzle[1]).split(' ') number_of_players = int(puzzle_input[0]) last_marble = int(puzzle_input[6]) scores = [0] * number_of_players marble_to_play = 1 marbles = FunkyStructure(0) for puzzle_part in (1, 2): while marble_to_play <= last_marble: if marble_to_play % 23 == 0: marbles.rotate_by(7) removed_marble = marbles.pop_tail()
circle_size = len(circular_list) running_total = 0 for index in range(circle_size): index2 = (index + offset) % circle_size if circular_list[index] == circular_list[index2]: running_total += circular_list[index] return running_total puzzle = (2017, 1) # Initialise the helper library aoc = AOCLib(puzzle[0]) # Get the puzzle input as a list of integers puzzle_input = aoc.get_puzzle_input(puzzle[1], AOCLib.sequence_to_int) # print(puzzle_input) # Puzzle solution part 1: aoc.print_solution(1, solve_puzzle(puzzle_input, 1)) # Puzzle solution part 2 aoc.print_solution(2, solve_puzzle(puzzle_input, len(puzzle_input)//2))
from lib.aoclib import AOCLib puzzle = (2017, 6) # Initialise the helper library aoc = AOCLib(puzzle[0]) # Get the puzzle input puzzle_input = aoc.get_puzzle_input(puzzle[1], lambda x: [int(y) for y in x.split('\t')]) # print(puzzle_input) # Puzzle solution parts 1 and 2 banks = puzzle_input[:] number_of_banks = len(banks) state_history = {} cycles = 0 while True: state_history[tuple(banks)] = cycles biggest_bank_size = -1 for bank_index, check_bank in enumerate(banks): if check_bank > biggest_bank_size: biggest_bank = bank_index biggest_bank_size = check_bank