for line in f: line = line.strip() if '#ip' in line: pointer = int(line.split()[-1]) else: line = line.split() line = [line[0]] + list(map(int, line[1:])) instructions.append(line) # register = [0, 10664125, 45538, 22, 0, 175] # register = [0, 2813690, 177, 28, 1, 1] register = [2813690, 431003, 65536, 21, 0, 253] # register = [0] * 6 # register[0] = 11592302 register[0] = 0 computer = Computer(instructions=instructions, register=register, pointer=pointer) # computer.run_until_finished() output = [] output_set = set() instr_index = 0 while instr_index < len(computer.instructions): instr = computer.instructions[computer.get_pointer()] if instr[0] == 'eqrr': val = computer.register[1] if val in output_set: print(f'FOUND A REPEATED NUM') break output_set.add(val) output.append(val) print(output)
def main(): colorama.init() inputFile = basename(__file__)[:2] + '-input.txt' lines = [] with open(inputFile, 'r') as infile: for line in infile: lines.append(line.strip()) programme = parse(lines[0]) image = Image() m1 = 0.48 m2 = 0.36 y = 0 width = 0 while width < 300: x1 = y / m1 x2 = y / m2 width = x2 - x1 y += 1 print('at y={0} x1={1} x2={2} width={3}'.format(y, x1, x2, width)) y1 = 411 for y in [y1, y1 + 99]: for x in range(910, 1250): computer = Computer(programme.copy(), [], debug=False) computer.input(x) computer.input(y) computer.run() val = computer.read() image.set(XY(x, y), val) extents = [] for y in [y1, y1 + 99]: print('y', y) left = None right = None for x in range(0, 1250): coord = XY(x, y) value = image.get(coord) if value == 1: print(Fore.CYAN + '1', end='') if left is None: left = x right = x # elif value == 0: else: print(Fore.LIGHTBLACK_EX + '.', end='') print(Fore.RESET + Back.RESET, end='') extents.append((left, right)) print('') print('tractor range {0} to {1}'.format(left, right)) print('\n\n') y1_end = extents[0][1] y2_start = extents[1][0] print('y2 start: ', y2_start) print('overlap', (y1_end - y2_start) + 1) # 1081 * 10000 + 414 = 10810414 too high # print(y2_start * 10_000 + y1) # 10790413 too high print(y2_start * 10_000 + y1) # 10730411
from computer import Computer with open('input05', 'r') as data: data = list(map(int, data.read().split(','))) tape = Computer(int_code=data) print(*tape.compute_n(niter=2, feed=(1, 5)))
1002, 9, 2, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 3, 9, 1001, 9, 2, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 99, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1001, 9, 2, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 99, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 99, 3, 9, 1001, 9, 2, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 99 ] comp = Computer([]) curr = 0 for a in range(0, 5): for b in range(0, 5): for c in range(0, 5): for d in range(0, 5): for e in range(0, 5): if len(set([a, b, c, d, e])) != 5: continue compA = Computer(copy(data)) compB = Computer(copy(data)) compC = Computer(copy(data)) compD = Computer(copy(data)) compE = Computer(copy(data)) out, _ = compA.execute([a, 0])
from eve import Eve from flask import jsonify from computer import Computer import psutil app = Eve() Computer = Computer() #Processor root information @app.route('/computer') def getProcessorRootInfo(): return jsonify("REST API for computer information") #Processor information @app.route('/computer/processor') def getProcessorInfo(): return jsonify(Computer.name) #Disk information @app.route('/computer/disk') def getDiskInfo(): return jsonify(Computer.disk_usage) #Memory information @app.route('/computer/memory') def getMemoryInfo(): return jsonify(Computer.virtual_memory)
if __name__ == '__main__': input_space = Space([Real(0., 10., transform="normalize", name="t")]) parameter_space = Space([Real(0., 1., transform="normalize", name="x")]) # input_space = Space([Real(0., 0.0001, "uniform", "normalize", name="t")]) # parameter_space = Space([Real(-1., 1., "uniform", "normalize", name="x")]) output_space = Space([Real(float('-Inf'), float('Inf'), name="time")]) constraints = {"cst1": "x >= 0. and x <= 1."} # problem = TuningProblem(input_space, parameter_space,output_space, objectives, constraints, models) # with performance model problem = TuningProblem(input_space, parameter_space, output_space, objectives, constraints, None) # no performance model computer = Computer(nodes=1, cores=16, hosts=None) options = Options() options['model_restarts'] = 10 options['distributed_memory_parallelism'] = False options['shared_memory_parallelism'] = False options['objective_evaluation_parallelism'] = False options['objective_multisample_threads'] = 1 options['objective_multisample_processes'] = 1 options['objective_nprocmax'] = 1 options['model_processes'] = 1 # options['model_threads'] = 1 # options['model_restart_processes'] = 1
from computer import Computer if __name__ == "__main__": import doctest doctest.testmod() with open('12input.txt', 'r') as inputfile: lines = inputfile.readlines() part1 = Computer() part1.run(lines) print("Part 1: {}".format(part1.a)) part2 = Computer() part2.c = 1 part2.run(lines) print("Part 1: {}".format(part2.a))