def solve(): # Setup computer print("Solving Day 13") program = list(map(int, aoc.read_program('13.txt'))) computer = intcode.IntCodeComputer(program, pause_on_output=True) state = defaultdict[int] while computer.status != intcode.StatusFlag.FINISHED: # parse 3 output values for i in range(3): try: computer.run() except intcode.ProgramFinished: print("Program end found") break if computer.status != intcode.StatusFlag.FINISHED: x, y, t_id = computer.output_value computer.output_value = None state[(x, y)] = t_id total_block_tiles = sum( [t_id == TileID.BLOCK.value for t_id in state.values()]) print(f"Total Blocks: {total_block_tiles}")
def best_base(txtfile): # Preprocess data contents = aoc.read_program(txtfile) table, height, width = transform_program(contents) # Locate asteroids asteroids = locate_asteroids(table, height, width) # Calculate maximum number of visible asteroids from the best base location max_seen, where_seen = how_well_can_i_see(asteroids) print('Day 10, Part 1 - Max asteroids visible = {} from asteroid at {}' .format(max_seen, where_seen)) return max_seen, where_seen
def preprocess_transmission(x, y, txtfile): # load transmission information transmission_received = aoc.read_program(txtfile) # Process transmission dimensions digits_per_image_layer = x * y transmission_length = len(transmission_received) image_count = transmission_length // digits_per_image_layer image_count_error = transmission_length % digits_per_image_layer if image_count_error: raise Exception('Transmission corrupted. Partial final image') print('length of transmission = {}, number of images = {}'.format( transmission_length, image_count)) # Find number of image layers image_layers = transform_program(transmission_received, image_count, digits_per_image_layer) return digits_per_image_layer, image_count, image_layers
def blast_rotation(txtfile): # Preprocess data contents = aoc.read_program(txtfile) table, height, width = transform_program(contents) # Locate asteroids asteroids = locate_asteroids(table, height, width) # Calculate maximum number of visible asteroids from the best base location max_seen, where_seen = how_well_can_i_see(asteroids) # create vector of the seen asteroid locations from the new base remaining_asteroids = other_asteroids(asteroids, where_seen) lst = asteroids_seen_from_new_base(remaining_asteroids, where_seen) lst = lst.loc[lst.groupby('theta')['radius'].idxmin()] # Sort the vector to enable visual determination of Part 2 answer lst = lst.sort_values('theta').reset_index() return lst
def __init__(self, board_dim=(25, 25), ai=False): self.automated = ai game_input = self.game_input() next(game_input) program = list(map(int, aoc.read_program('13.txt'))) program[0] = 2 # Set up for unlimited play self.computer = intcode.IntCodeComputer(program, input_user=game_input, pause_on_output=True) self.state = defaultdict(int) self.score = 0 self.last_input = None self.board_dim = board_dim self.char_map = { 0: ' ', 1: '\u2588', 2: '\u2591', 3: '\u2501', 4: '\u25cf' }
# # process inner sums # eris_copy = check_adjacent_folding(eris, layers_needed) # eris_copy[:, 3, 3] = 0 # eris = eris_copy # # count critters # print(f"Day 24, Part 2 - There are currently " # f"{count_critters(eris, layers_needed)}" # f" bugs present.") # %% Production Environment txtfile = "../data/AoC2019_day_24_input.txt" contents = aoc.read_program(txtfile) eris = transform_program(contents) minutes = 50 layer = day24_part1(eris, minutes) biodiversity_rating = biodiversity(layer) print(f"Day 24, Part 1 - Biodiversity rating = {biodiversity_rating}") txtfile = "../data/AoC2019_day_24_input.txt" contents = aoc.read_program(txtfile) eris_initiator = transform_program(contents) minutes = 200 day24_part2(eris_initiator, minutes)
if order['chain_reaction_level'] == reaction_level_index - 1: print('yes') print(order['recipe'].items()) for chem_name, amount in order['recipe'].items(): print(f"{chem_name} {amount}") order_key_index = create_order(ledger, inventory, orders, chemicals, order_key_index, chem_name, reaction_level_index) # %% Development Environment txtfile = "../data/AoC2019_day_14_input.txt" raw_data = aoc.read_program(txtfile) data = transform_input(raw_data) chemicals = create_chemicals_dictionary(data) ledger = create_dictionary(data) inventory = create_dictionary(data) order_key_index = 0 reaction_level_index = 0 orders = {} chem_name = 'FUEL' order_key_index = create_order(ledger, inventory, orders, chemicals, order_key_index, chem_name, reaction_level_index)
quarter_moons = position_at_end_of_time_step(harvest_moons) e = energy(quarter_moons) time_steps += 1 if not (time_steps % 100000): print('Passing time step...{0:,d}'.format(time_steps)) # if quarter_moons == new_moons: # break if e == 0: break print_format(quarter_moons, time_steps) print('Total energy in the system = {}'.format(e)) print() # %% Set up variables pairs = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]] # %% Development Environment txtfile = "../data/AoC2019_day_12_input.txt" start = aoc.read_program(txtfile) start_vector = transform_input(start) new_moons = convert_moon_list_to_dictionary(start_vector, 3, 2, 4) full_moons = convert_moon_list_to_dictionary(start_vector, 3, 2, 4) moon_shot(new_moons, full_moons, 100000000000) # %% Production Environment