def main(): opcode_list = fa.read_input_values('day13_puzzle_input.txt') opcode_list = [int(thing) for thing in opcode_list] computer = Computer(opcode_list) blocks_num = 0 game_ch = {0: ' ', 1: '|', 2: '#', 3: '-', 4: '0'} game_code = [] while not computer.done: output = computer.calculate() if not computer.done: game_code.append(output) game_map = [['.' for _ in range(43)] for _ in range(23)] for idx in range(0, len(game_code), 3): if game_code[idx + 2] == 2: blocks_num += 1 x, y, ch = game_code[idx], game_code[idx + 1], game_ch[game_code[idx + 2]] ## print(idx, x,y,ch) game_map[y][x] = ch result = 0 for row in game_map: print(row) result += row.count('#') print(result, blocks_num)
def main(): opcode_list = fa.read_input_values('day13_puzzle_input.txt') opcode_list = [int(thing) for thing in opcode_list] opcode_list[0] = 2 computer = Computer(opcode_list) ball_x = 0 paddle_x = 0 joystick_input = 0 scrole = 0 game_ch = {0: ' ', 1: '|', 2: '#', 3: '-', 4: '0'} game_code = {} blocks_num = 0 ball_draw = False paddle_draw = False while not computer.done: x = computer.calculate() y = computer.calculate() title = computer.calculate() if not (x == -1 and y == 0): if title != None: game_code[(x, y)] = game_ch[title] elif x == -1 and y == 0: scrole = title if title == 3: paddle_x = x paddle_draw = True if ball_draw == True: ball_draw = False paddle_draw = False joystick_position(ball_x, paddle_x, computer) elif title == 4: ball_x = x ball_draw = True if paddle_draw == True or paddle_x != 0: ball_draw = False paddle_draw = False joystick_position(ball_x, paddle_x, computer) elif title == 2: blocks_num += 1 ## if blocks_num == 0: ## break ## computer.done = False print('*' * 20) print('* Scrole:', f'{scrole:8}', '*') print('*' * 20)
def main(): current_position = 0 opcode_list = fa.read_input_values('day5_puzzle_input.txt') opcode_list = [int(thing) for thing in opcode_list] computer = Computer(opcode_list) while not computer.done: computer.calculate(5) print(computer.output)
def main(): opcode_list = fa.read_input_values('day11_puzzle_input.txt') opcode_list = [int(thing) for thing in opcode_list] painting = Robot_painter(opcode_list) painting.paint() print(f"Part 1: {len(painting.painted.keys())}") letter_painting = Robot_painter(opcode_list[:], 1) letter_painting.paint() print(f"Part 1: {len(letter_painting.painted.keys())}") letter_painting.show_painting()
def main(): opcode_list = fa.read_input_values('day9_puzzle_input.txt') opcode_list = opcode_list + [0] * 2000 opcode_list = [int(thing) for thing in opcode_list] input_signal = 1 amp1 = Computer(opcode_list[:]) output_signal1 = amp1.calculate(input_signal) print(output_signal1) input_signal = 2 amp2 = Computer(opcode_list[:]) output_signal2 = amp2.calculate(input_signal) print(output_signal2)
def main(): #Take optcode from file opcode_list = fa.read_input_values('day17_puzzle_input.txt') opcode_list = [int(thing) for thing in opcode_list] task_map_code = create_map(opcode_list) bot_x, bot_y = draw_map(task_map_code) result1 = calculate_result_part1(task_map_code) ### Print First Result ### print('Part1: ', result1) bot_path = calculate_path(task_map_code, bot_x, bot_y) print(bot_path)
def main(): template = "Part{} Answer: {}" list1 = fa.read_input_values('day3_puzzle_input.txt') list2 = fa.read_input_values('day3_puzzle_input.txt', 1) wire1 = build_wire(list1, {}) wire2 = build_wire(list2, {}) cross_wire = list(set(wire1.keys()) & set(wire2.keys())) result1 = manhattan_distance(cross_wire[0]) for coord in cross_wire: result1 = min(result1, manhattan_distance(coord)) print(template.format(1, result1)) steps = wire1[cross_wire[0]] + wire2[cross_wire[0]] for coord in cross_wire: if steps > wire1[coord] + wire2[coord]: steps = wire1[coord] + wire2[coord] print(template.format(2, steps))
def main(): opcode_list = fa.read_input_values('day7_puzzle_input.txt') opcode_list = [int(thing) for thing in opcode_list] ls = [x for x in range(5)] ls_full = [ls[:]] while next_step(ls): ls_full.append(ls[:]) max_output_signal = 0 for ls_permutation in ls_full: output_signal = 0 for phase in ls_permutation: amp = Computer(opcode_list[:]) amp.inputs.append(phase) output_signal = amp.calculate(output_signal) max_output_signal = max(max_output_signal, output_signal) print('Part1:', max_output_signal) ls = [x for x in range(5, 10)] ls_full = [ls[:]] while next_step(ls): ls_full.append(ls[:]) max_output_signal = 0 for ls_permutation in ls_full: output_signal = 0 amps = [Computer(opcode_list) for _ in range(5)] for amp, phase_setting in zip(amps, ls_permutation): amp.inputs.append(phase_setting) while amps[-1].done == False: for amp in amps: amp.calculate(output_signal) output_signal = amp.output max_output_signal = max(output_signal, max_output_signal) print(f"Part 2: {max_output_signal}")
def main(): ## task_test1 = '12345678' ## task_test2 = list('03036732577212944063491565474664') task = fa.read_input_values('day16_puzzle_input.txt') t = fft(task[0], 100) result = ''.join(map(str, t)) print('Part1:', result) task = task[0] * 10000 offset = int(''.join([str(d) for d in task[:7]])) task_list = task[offset:] task_list = [int(x) for x in task_list] for iteration in range(100): restsum = sum(task_list) for i, n in enumerate(task_list): task_list[i] = abs(restsum) % 10 restsum -= n result = ''.join(str(n) for n in task_list[:8]) print('Part 2: ', result)