def run_self_test(self, test): stream = io.StringIO() self.save_test(stream, test) n = len(test) out = gamma.call_with_io( self.brute_path if n <= 8 else self.model_path, stream.getvalue()) return out.strip()
def run_self_test(self, test): stream = io.StringIO() self.save_test(stream, test) n, q = len(test[0]), len(test[1]) out = gamma.call_with_io(self.brute_path if False else self.model_path, stream.getvalue()) return [int(x) for x in out.split("\n") if x]
def main(command="liczba-min.exe", verbose=True): for i in range(100): h, d, s = [random.randint(1, 40000) for _ in range(3)] got = int(call_with_io(command, f"{h} {d} {s}")) exp = sorted([h, d, s])[1] // 2 if got != exp: print(f"{i}:", h, d, s) print(f"{got} != {exp}") print("!@#") return False else: pass return True
def main(command="liczba-min.exe", verbose=True): for i in range(100): p, k, s, d = [ random.randint(*b) for b in [(1, 30), (1, 20), (0, 59), (1, 100)] ] got = int(call_with_io(command, f"{p} {k} {s} {d}")) exp = (60 * k + s - d) // p if exp < 0: continue if got != exp: print(f"{i}:", p, k, s, d) print(f"{got} != {exp}") print("!@#") return False else: pass return True
def run_self_test(self, test, n=n): stream = io.StringIO() self.save_test(stream, test) return int(call_with_io(COMMAND, stream.getvalue()))
r += sigma(at(min(y, x2), y), 1, cut(x1, x2, -y, y)) r += rowd(x1, min(x2, -y - 1), y) + rowd(max(x1, y + 1), x2, y) else: y = -y r += sigma(at(max(-y, x1), -y), 1, cut(x1, x2, -y, y)) r += rowd(x1, min(x2, -y - 1), -y) + rowd(max(x1, y + 1), x2, -y) return r def query(x1, y1, x2, y2): r = 0 for y in range(y1, y2 + 1): r += row(x1, x2, y) print(r % (10**9 + 7)) return r import random from gamma import call_with_io for i in range(32): print(i) x1, x2 = sorted((random.randint(-10, 10), random.randint(-10, 10))) y1, y2 = sorted((random.randint(-10, 10), random.randint(-10, 10))) s1 = query(x1, y1, x2, y2) % (10**9 + 7) s2 = int( call_with_io("spiral-beta.py", "100000 1\n{} {} {} {}".format(x1, y1, x2, y2))) print(x1, y1, x2, y2, "->", s1, s2) assert s1 == s2
from gamma import call_with_io import tqdm import os import time T = 2**16 use_tqdm = True it = tqdm.tqdm(range(T)) if use_tqdm else range(T) def tprint(*args, **kwargs): if not use_tqdm: print(*args, **kwargs) times = [] for i in it: tprint(f"Test {i}") r = call_with_io("nie-di.exe", f"{a}\n{b}") print() #print("Times:", times) os.system("pause")
from gamma import call_with_io class Test: def __init__(self, Y, a, b): self.Y, self.a, self.b = Y, a, b @classmethod def random(cls, N, E): n = random.randint(*N) a, b = sorted(random.sample(range(1, n + 1), 2)) return cls([random.randint(*E) for _ in range(n)], a, b) def __str__(self): return "{} {} {}\n{}".format(len(self.Y), self.a, self.b, " ".join(str(y) for y in self.Y)) for _ in range(1024): T = Test.random((2, 100), (0, 10**9)) r2 = int(call_with_io("rze-n3", str(T)).strip()) print(">", r2) #print(r1, r2) #if r1 != r2 or r1 > 2**50: # with open("failed{}.in".format(random.randint(0, 2**16 - 1)), "w") as f: # f.write(str(T)) # print("!@#") # break
from gamma import call_with_io import random from string import ascii_lowercase for i in range(1 << 18): if i % 32 == 0: print(i) n = 2 * random.randint(1, 4) s = [random.choice(ascii_lowercase) for _ in range(n // 2)] s += s[::-1] b = random.randint(0, 1) if b: for _ in range(random.randint(1, n // 2)): i = random.randint(0, n // 2 - 1) j = 2 * (n // 2 - 1) - i + 1 s[i], s[j] = random.sample(ascii_lowercase, 2) s = "".join(s) print(s) m = random.choice((0, n)) r = call_with_io("pal.exe", f"{m}\n" + s) assert r == "TAK" or r == "NIE" print(b, r) assert b == (r == "NIE")
def run_self_test(self, test): stream = io.StringIO() self.save_test(stream, test) out = gamma.call_with_io(self.exe_path, stream.getvalue()) return int(out.strip())
from gamma import call_with_io from math import factorial, sqrt, floor from random import randint for i in range(2**20): rt = floor(sqrt(i)) b, a = sorted((randint(0, rt), randint(0, rt))) c = randint(1, 10**6) p = 1 for x in range(b + 1, a + 1): p *= x p %= c q = int(call_with_io("ilo.exe", f"{a} {b} {c}")) print(a, b, p, q) assert p == q
from random import * from pathlib import * from shutil import * import glob from gamma import call_with_io p = Path('./permutacja-testy/') try: rmtree(p) except FileNotFoundError: pass p.mkdir() def gen(n): t = [i + 1 for i in range(n)] shuffle(t) return f'{n}\n{" ".join(map(str, t))}\n' for i in range(256): (p / f'{i}.in').write_text(gen(10)) for name in glob.glob("permutacja-testy/*.in"): with open(name[:-3] + ".out", "w") as file: file.write(call_with_io(f"permutacja.exe < {name}"))
from gamma import call_with_io import random class Test: def __init__(self, P): self.P = P @classmethod def random(cls, N, E): return cls([tuple(sorted((random.randint(*E), random.randint(*E)), reverse=True)) for _ in range(random.randint(*N))]) def __str__(self): s = f"{len(self.P)}\n" for a, b in self.P: s += f"{a} {b}\n" return s.strip() for i in range(32): print("$", i) T = Test.random((1, 300), (0, 10**9)) exp = call_with_io("b-n3", str(T)) got = call_with_io("b", str(T)) if got != exp: print("!@#") print(T) print(">>>", got, exp) with open(f"failed{random.randint(0, 2**16 - 1)}.in", "w") as f: f.write(str(T)) break
from gamma import call_with_io brute = "brakuje.exe" model = "brakuje-beta.exe" S = "921" for n in range(1, 10**5 + 1): brute_result = call_with_io(brute, f"{S} {n}") model_result = call_with_io(model, f"{S} {n}") print(n, "->", brute_result, model_result) assert brute_result == model_result