def run_testcase(testcase, args): testcase = path(testcase).name config = ConfigParser() config.read(['default.cfg', 'main.cfg', args.config]) update_config(config, 'score', args.score) update_config(config, 'solve', args.solve) sc_fn = get_function('score', config) run_folder = setup_run_folder(sys.argv, config, testcase) init_log(testcase) tear_down_streams = setup_stdstreams(run_folder) log.debug('Running testcase {}'.format(testcase)) inp = get_in_file_content(testcase) solve_args = {} for kv in args.solve_args.split(','): if '=' in kv: k, v = kv.split('=') solve_args[k] = v solve_args['log'] = log solve_args['testcase'] = testcase solve_args['folder'] = run_folder orig_module_name = config.get('solve', 'module') solve_args['module_name'] = sanitize_module_name(orig_module_name) get_ans = get_ans_fn(config, inp) def run(solve_args): solve_args_orig = dict(solve_args) ans = get_ans(solve_args) process(inp, ans, solve_args_orig, sc_fn) rounds = 1 if args.seed else args.iterations for i in range(rounds): seed = args.seed if args.seed else ri(0, 10**6 - 1) log.debug('seed: {:<6}, test#: {}'.format(seed, i)) sa = dict(solve_args) sa['iter'] = i sa['seed'] = seed run(sa) tear_down_streams()
import argparse import random import sys sys.path.extend(['..', '.']) from collections import * from dataparser import parse from util import get_in_file_content # inp is an input file as a single string # return your output as a string def solve(inp, args): # TODO: Solve the problem random.seed(args['seed']) ns = parse(inp) return '0' if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('in_file') args = parser.parse_args() inp = get_in_file_content(args.in_file) out = solve(inp, {'seed': 0}) print('\n'.join(['OUT:', '=========', out]))
print(inp) print('==============') ns = parse(inp) # TODO: display inp in readable form! def get_tasks(): parser = argparse.ArgumentParser() parser.add_argument('testcase', nargs='?', default=None) parser.add_argument('-a', '--all', action='store_true') args = parser.parse_args() if not (args.testcase or args.all): print('provide either all: -a or a testcase.') exit() tasks = [] if args.all: for f in sorted(glob.glob('in/*.in')): tc_name = path(f).name tasks.append(tc_name) else: tc_name = path(args.testcase).name tasks.append(tc_name) return tasks if __name__ == '__main__': tasks = get_tasks() for tc_name in tasks: inp = get_in_file_content(tc_name) test(tc_name, inp)