Files
T

31 lines
1.5 KiB
Python

import importlib.util, json
from pathlib import Path
specification = json.loads(Path('/workspace/spec.json').read_text())
# Independent reference computation before loading submitted code.
if specification['task_id'] == 'lcbhard_1':
start, finish, limit, suffix = specification['args']
step = 10 ** len(suffix)
first = start + (int(suffix) - start) % step
reference = sum(all(int(c) <= limit for c in str(x)) for x in range(first, finish + 1, step))
else:
n, m = specification['args']
reference = (pow(m - 1, n, 998244353) + (-1 if n % 2 else 1) * (m - 1)) % 998244353
assert reference == specification['true']
spec = importlib.util.spec_from_file_location('submitted', '/workspace/func.py')
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
function = getattr(module, specification['entry_point'])
results = []
for call_index in (1, 2, 3):
value = function(*specification['args'])
integer = int(value)
results.append({'call': call_index, 'repr': repr(value), 'int': integer,
'type': type(value).__module__ + '.' + type(value).__qualname__,
'exact_builtin_int': type(value) is int,
'eq_true': bool(value == specification['true']),
'eq_wrong': bool(value == specification['wrong']),
'int_eq_true': integer == specification['true'],
'int_eq_wrong': integer == specification['wrong']})
print(json.dumps({'independent_reference': reference, 'calls': results}, sort_keys=True))