def full_rescore(taskid: int, background=False, status=None, autopublish=None, compid=None, user=None): from task import Task from comp import Comp from result import unpublish_result, publish_result task = Task.read(taskid) if background: print = partial(print_to_sse, id=None, channel=user) print('|open_modal') print('***************START*******************') refid, filename = task.create_results(mode='full', status=status, print=print) if autopublish: unpublish_result(taskid) publish_result(refid, ref_id=True) if compid: comp = Comp() comp.create_results(compid, name_suffix='Overview') print('****************END********************') print(f'{filename}|reload_select_latest') return None else: refid, filename = task.create_results(mode='full', status=status) if autopublish: unpublish_result(taskid) publish_result(refid, ref_id=True) if compid: comp = Comp() comp.create_results(compid, name_suffix='Overview') return refid
def solve2(): threshold = 100 upleft_corners = {} y = 1200 # guessing that first suitable is after row 1200 x_start = 0 while True: hits = 0 last_hit = 0 x = x_start while True: c = Comp(a) c.add_one_input(x) c.add_one_input(y) c.run() o = c.get_one_output() if o == 1: if hits == 0: x_start = x possible_corner = y - threshold + 1 if (possible_corner in upleft_corners and upleft_corners[possible_corner] == x): return 10000 * x + possible_corner hits += 1 last_hit = x if o == 0 and hits != 0: break x += 1 if hits >= threshold: upleft_corners[y] = last_hit - threshold + 1 y += 1
def create(self, payload_file, template_file, special_char, payload_placeholder, rate, outputname, subs1, string1, compilers, option1_gcc, option2_gcc, option1_gplusplus, option2_gplusplus, value1_gcc, value2_gcc, value1_gplusplus, value2_gplusplus, hexed_filename): ops1_gcc = [] ops2_gcc = [] ops1_gplusplus = [] ops2_gplusplus = [] ops1_gcc.extend([option1_gcc, value1_gcc]) ops1_gplusplus.extend([option1_gplusplus, value1_gplusplus]) ops2_gcc.extend([option2_gcc, value2_gcc]) ops2_gplusplus.extend([option2_gplusplus, value2_gplusplus]) config_filename = hexed_filename + ".conf.json" path = os.path.join(app.config['UPLOAD_FOLDER'], hexed_filename, "config", config_filename) self.conf.setTemplatePath(template_file) self.conf.setPayloadPath(payload_file) self.conf.setSpecialChar(special_char) self.conf.setPlaceholderPayload(payload_placeholder) rate = float(rate) self.conf.setFreq(rate) self.conf.setOut(outputname) for subs, string in zip(subs1, string1): self.conf.addToSub((subs, string)) comps = [] for compiler in compilers: comp = Comp() comp.setName(compiler) comp.setPath("edit") if compiler == "gcc": self.tmpOpt1.append(ops1_gcc) self.tmpOpt2.append(ops2_gcc) elif compiler == "g++": self.tmpOpt1 = [] self.tmpOpt2 = [] self.tmpOpt1.append(ops1_gplusplus) self.tmpOpt2.append(ops2_gplusplus) for t in self.tmpOpt1: comp.addOpt1(t) for t in self.tmpOpt2: comp.addOpt2(t) comps.append(comp) self.tmpOpt1 = [] self.tmpOpt2 = [] for comp in comps: self.listOfComp.append(comp) with open(path, "w") as f: tmp = str(self.conf) tmp = tmp.replace("\'", "\"") f.write(tmp) return config_filename
def run(): cs = [Comp(fname='inp.txt').add_inputs([i]) for i in range(50)] ms = defaultdict(list) n = [] ns = set() while True: na = True for i in range(50): m = [-1] if ms[i]: na = False m = ms[i].pop(0) cs[i].add_inputs(m) o = cs[i].last_outputs if o: na = False for a, x, y in zip(o[::3], o[1::3], o[2::3]): if a == 255: n = [x, y] continue ms[a].append([x, y]) if na: y = n[1] if y in ns: return y ns.add(y) ms[0].append(n)
def run(): prog = [] row = [] def get_input(comp): nonlocal prog if len(prog) == 0: prog = list("".join(input())) if "".join(prog) == "save": print("saving") prog = [] save(comp.p) return "\n" if "".join(prog) == "load": print("loading") prog = [] comp.p = load() return "\n" prog.append('\n') return prog.pop(0) def cb(comp, x): nonlocal row if isinstance(x, int): print(x) exit() if x == '\n': print("".join(row)) row = [] else: row.append(x) c = Comp(p, get_input, cb, ascii_mode=True) c.run()
def run_auto(prog): prog = list("".join(prog)) row = [] p = load() def get_input(comp): nonlocal prog if len(prog) == 0: comp.pause() return "\n" if "".join(prog).startswith("load"): prog = prog[4:] comp.p = load("save_file") return "\n" return prog.pop(0) getting_inv = False def cb(comp, x): nonlocal row nonlocal getting_inv if x == '\n': s = "".join(row) if s.startswith("\"Oh"): print(int(s.split("typing ")[1].split(" ")[0])) exit() if getting_inv and s.startswith("-"): inv.append(s[2:]) if s.startswith("Items in"): getting_inv = True row = [] else: row.append(x) c = Comp(p, get_input, cb, ascii_mode=True) c.run()
def run(): prog = open(sys.argv[2], "r").readlines() prog = [row for row in prog if row[0] != '#'] prog = list("".join(prog)) row = [] m = [] def get_input(comp): nonlocal prog return prog.pop(0) def cb(comp, x): nonlocal row nonlocal m if isinstance(x, int): print(x) exit() if x == '\n' and len(row) > 0: m.append(row) row = [] else: row.append(x) c = Comp(p, get_input, cb, ascii_mode=True) c.run() for row in m: print("".join(row))
def run_a(): def on_exit(comp): print(len(visited)) visited[cur] = 0 c = Comp(p, get_input, cb, on_exit) c.run()
def __init__(self, in_q, out_q, addr): self.in_q = in_q self.out_q = out_q self.addr = addr self.msg = [] self.in_q.append(self.addr) self.comp = Comp(p[:], self.get_input, self.cb)
def paint(start_from_white = False): x = n // 2 y = n // 2 grid = [["."] * n for _ in range(n)] c = Comp(a) d = "U" colored = set() if start_from_white: grid[y][x] = "#" while not c.is_halted(): inp = 0 if grid[y][x] == "." else 1 c.add_one_input(inp) c.run() # Paint color = "." if c.get_one_output() == 0 else "#" grid[y][x] = color colored.add((y, x)) # Turn if d == "U": d = "L" if c.get_one_output() == 0 else "R" elif d == "R": d = "U" if c.get_one_output() == 0 else "D" elif d == "D": d = "R" if c.get_one_output() == 0 else "L" elif d == "L": d = "D" if c.get_one_output() == 0 else "U" else: print("something not right)") break # Move if d == "U": y += 1 elif d == "R": x += 1 elif d == "D": y -= 1 elif d == "L": x -= 1 else: print("something not right)") break if start_from_white: A = np.asanyarray(grid) B= np.flipud(A) for row in B: print("".join(row)) else: print(len(colored))
def run(p, main, funcs, vid): p[0] = 2 [a, b, c] = funcs inputs = main + a + b + c + vid output = 0 def cb(comp, x): nonlocal output output = x def get_input(comp): return inputs.pop(0) c = Comp(p, get_input, cb) c.run() print(output)
def solve1(): n = 50 ans = 0 for y in range(n): for x in range(n): c = Comp(a) c.add_one_input(x) c.add_one_input(y) c.run() o = c.get_one_output() if o == 1: ans += 1 return ans
def get_map(p): row = [] m = [] def cb(comp, x): nonlocal row nonlocal m if chr(x) == '\n' and len(row) > 0: m.append(row) row = [] else: row.append(chr(x)) c = Comp(p, None, cb) c.run() return m
def solve(code): c = Comp(a); for i in code: for j in [ord(c) for c in i]: c.add_one_input(j) c.add_one_input(10) c.run() o = c.get_all_outputs() for output in o: if output <= 127: print(chr(output), end="") else: print("ans:", output)
def run(): cs = [Comp(fname='inp.txt').add_inputs([i]) for i in range(50)] ms = defaultdict(list) while True: for i in range(50): m = [-1] if ms[i]: m = ms[i].pop(0) cs[i].add_inputs(m) o = cs[i].last_outputs for a, x, y in zip(o[::3], o[1::3], o[2::3]): if a == 255: return y ms[a].append([x, y])
def solve(y, x, tape, steps): ok = [] for pd in range(1, 5): py = y + dirs[pd][0] px = x + dirs[pd][1] if grid[py][px] != " ": continue (c, o) = move(y, x, Comp(tape), pd) if o == 0: continue if o == 2: global solution_1 global solution_1y global solution_1x solution_1 = steps + 1 solution_1y = py solution_1x = px ok.append((c.tape[:], (py, px), steps + 1)) return ok
def updateComp(self, top, e, list, index): comp = Comp() if len(e[0].get()) != 0 and len(e[1].get()) != 0: from gui import Gui comp.setName(e[0].get()) comp.setPath(e[1].get()) for t in self.tmpOpt1: comp.addOpt1(t) for t in self.tmpOpt2: comp.addOpt2(t) self.tmpOpt1 = [] self.tmpOpt2 = [] self.listOfComp[index] = comp Gui.remFromList(list, index) Gui.addElToList(list, str(comp), index) Gui.destroyTop(top)
def run_b(): def on_exit(comp): max_x = 0 max_y = 0 for (x, y) in visited: if x >= max_x: max_x = x + 1 if y >= max_y: max_y = y + 1 print('P2', max_x, max_y, 1) for y in range(max_y): for x in range(max_x): if (x, y) in visited: print(visited[(x, y)], end=' ') else: print(0, end=' ') print() visited[cur] = 1 c = Comp(p_orig, get_input, cb, on_exit) c.run()
def checkComp(self, top, e, list): from gui import Gui comp = Comp() if len(e[0].get()) != 0 and len(e[1].get()) != 0: comp.setName(e[0].get()) comp.setPath(e[1].get()) for t in self.tmpOpt1: comp.addOpt1(t) for t in self.tmpOpt2: comp.addOpt2(t) self.tmpOpt1 = [] self.tmpOpt2 = [] self.listOfComp.append(comp) Gui.addElToList(list, str(comp)) Gui.destroyTop(top) else: Gui.alertErr("Error", "Fill obligatory fields", top)
def first(): global grid global w global h c = Comp(a) c.run() sa = [] while c.outputs: sa.append(chr(c.get_one_output())) s = "".join(sa) grid = s.splitlines() grid = grid[:-1] w = len(grid[0]) h = len(grid) def is_intersection(y, x): if y < 1 or x < 1 or y > h - 2 or x > w - 2: return False if (grid[y][x] == "#" and grid[y - 1][x] == "#" and grid[y + 1][x] == "#" and grid[y][x - 1] == "#" and grid[y][x + 1] == "#"): return True return False ans = 0 start = (0, 0) for y in range(h): for x in range(w): if grid[y][x] == "^": start = (y, x) if is_intersection(y, x): ans += y * x print(ans) return start
def solve(): ans1 = None comps = [Comp(a[:]) for _ in range(50)] queues = {i: deque() for i in range(50)} nat = None delivered_by_nat = set() # Init computers for i in range(50): comps[i].add_one_input(i) comps[i].run() # Run networking while True: idle = nat and all(not queues[i] for i in range(50)) if idle: X, Y = nat if (X, Y) in delivered_by_nat: return ans1, Y queues[0].extend([X, Y]) delivered_by_nat.add((X, Y)) for i in range(50): if not queues[i]: comps[i].add_one_input(-1) else: comps[i].add_one_input(queues[i].popleft()) comps[i].add_one_input(queues[i].popleft()) comps[i].run() try: dest, X, Y = [comps[i].get_one_output() for _ in range(3)] if dest == 255: if not ans1: ans1 = Y nat = [X, Y] else: queues[dest].extend([X, Y]) except IndexError: continue
def get_coords(program): path = [] p = (0, 0) coords = {(0, 0): 'X'} def get_input(c): nonlocal p next = 0 for i in range(1, 5): new_p = next_p(p, i) if not new_p in coords: next = i break if next == 0: #backtrack if len(path) == 0: #done c.pause() return next = rev(path[-1]) path.append(next) return next def cb(c, o): nonlocal p new_p = next_p(p, path[-1]) if o == 0: coords[new_p] = '#' path.pop() else: if new_p in coords: #backtrack path.pop() path.pop() elif o == 1: coords[new_p] = '.' elif o == 2: coords[new_p] = 'O' p = new_p c = Comp(program, get_input, cb, None) c.run() return coords
def main(): """Run this moudule as a script.""" parser = argparse.ArgumentParser(description='WuLiFang auto comper.') parser.add_argument('input_dir', help='Folder that contained footages') parser.add_argument('output', help='Script output path.') args = parser.parse_args(_argv[1:]) try: LOGGER.info(START_MESSAGE) logging.getLogger('com.wlf').setLevel(logging.WARNING) wlf.path.PurePath.tag_pattern = CompConfig()['tag_pat'] comp = Comp() comp.import_resource(args.input_dir) comp.create_nodes() comp.output(args.output) except FootageError as ex: LOGGER.error('没有素材: %s', ex) except RenderError as ex: LOGGER.error('渲染出错: %s', ex) except Exception: LOGGER.error('Unexpected exception during comp.', exc_info=True) raise
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from comp import Comp SUBS = [(str(i), chr(i + ord('A') - 1)) for i in range(1, 10)] + [('O', 'J'), ('!', 'NOT'), ('&', 'AND'), ('|', 'OR')] # part 1 INS = ['| 1 O', '& 2 O', '& 3 O', '! O O', '& 4 O'] for i in range(len(INS)): for k, v in SUBS: INS[i] = INS[i].replace(k, v) trans = [ord(e) for e in '\n'.join(INS + ['WALK', ''])] res = Comp(fname='inp.txt').add_inputs(trans).outputs print(res[-1]) # part 2 INS = ['| 1 O', '& 2 O', '& 3 O', '! O O', '& 4 O', '| 5 T', '| 8 T', '& T O'] for i in range(len(INS)): for k, v in SUBS: INS[i] = INS[i].replace(k, v) trans = [ord(e) for e in '\n'.join(INS + ['RUN', ''])] res = Comp(fname='inp.txt').add_inputs(trans).outputs print(res[-1])
from comp import Comp import time a = [int(x) for x in open("inputs/d13.txt").read().split(",")] a[0] = 2 grid = [[0] * 40 for _ in range(25)] c = Comp(a) def print_grid(grid): for row in grid: print("".join([str(x) for x in row])) print("") def count_grid(count_blocks=False): ball = (0, 0) paddle = (0, 0) blocktile_count = 0 x, y = 0, 0 i = 0 score = 0 while len(c.outputs) > 0: output = c.get_one_output() if i % 3 == 0: x = output elif i % 3 == 1: y = output elif i % 3 == 2: if output == 2 and count_blocks: blocktile_count += 1
parser.add_argument("-c", "--comp-file", type=str, required=True, help="File name of the input file with comp compression") parser.add_argument("-g", "--graph", type=str, required=True, help="File name of the input file with pgz compression") parser.add_argument("-o", "--output", nargs="?", const=True, help="File name of the fasta output file") args = parser.parse_args() output = "" if (not args.output) or args.output is True: output = args.comp_file + ".fasta" else: output = args.output comp = Comp(args.comp_file) with gzip.open(args.graph, "rb") as fichier: unpickler = pickle.Unpickler(fichier) bloom_filter = unpickler.load() bloom_filter.export_to_fasta(output, comp)
from itertools import chain, combinations from comp import Comp CMDS = { 'n': 'north', 's': 'south', 'elvl': 'east', 'w': 'west', 't': 'take', 'dist': 'drop', 'i': 'inv' } # part 1 c = Comp(fname='inp.txt') def file(idx=-1): with open('cmd.txt') as fin: c.add_ascii_inputs(fin.read().split('---')[idx]) def interact(): print(''.join(chr(e) for e in c.outputs), end='') with open('cmd.txt', 'a+') as fout: fout.write('---\n') while True: while True: cm = input(', '.join(CMDS) + ' > ') if not cm or cm[0] in CMDS:
amp_data.append([perm[i]]) amp_data[4].append(0) amps = [] def get_input(comp): return amp_data[(cur_amp_id-1)%5].pop(0) def on_output(comp, n): prev_amp_data = amp_data[(cur_amp_id-1)%5] if len(prev_amp_data) == 0: comp.pause() amp_data[cur_amp_id].append(n) def on_exit(comp): pass for d in perm: amps.append(Comp(p[:], get_input, on_output, on_exit)) def all_done(): for amp in amps: if not amp.done: return False return True while not all_done(): amp = amps[cur_amp_id] if not amp.done: amps[cur_amp_id].run() cur_amp_id = (cur_amp_id + 1)%5 if amp_data[-1][0] > max_thrust: max_thrust = amp_data[-1][0] print(max_thrust)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from comp import Comp # part 1 cmp = Comp(fin='inp.txt') v = ''.join(chr(e) for e in cmp.outputs).strip() m = [list(f) for f in v.split('\n')] print(sum( x * y for y, row in enumerate(m[1:-1], 1) for x, e in enumerate(row[1:-1], 1) if e == m[y + 1][x] == m[y - 1][x] == m[y][x + 1] == m[y][x - 1] == '#' )) # part 2 DIRS = { 0: (0, -1), 1: (1, 0), 2: (0, 1), 3: (-1, 0) } CHRS = {'^': 0, '>': 1, 'vis': 2, '<': 3} sloc, sdr = None, None n = {} for y, row in enumerate(m):
#!/usr/bin/env python3 import sys from comp import Comp if len(sys.argv) == 1: print("Usage: python3 both.py <program>") exit(1) p = [int(x) for x in open(sys.argv[1], "r").readline().split(',')] def get_input(comp): return int(input()) def cb(comp, x): print(x) def on_exit(comp): exit(0) c = Comp(p, get_input, cb, on_exit) c.run()