From: Skullheadx <704277@pdsb.net> Date: Wed, 4 Jan 2023 22:40:50 +0000 (-0500) Subject: S1 2012 + grader X-Git-Url: http://git.skullheadx.com/nixos/blog/static/gitweb.js?a=commitdiff_plain;h=458b10e17badb05f1a1c32065dbd5386e5851015;p=CCC.git S1 2012 + grader --- diff --git a/.gitignore b/.gitignore index bc2a419..17ada73 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ *.exe .idea/CCC.iml .idea/misc.xml +*.in +*.out \ No newline at end of file diff --git a/Main/Python/2012/S1.py b/Main/Python/2012/S1.py new file mode 100644 index 0000000..2a76b58 --- /dev/null +++ b/Main/Python/2012/S1.py @@ -0,0 +1,21 @@ +from queue import Queue + + +J = int(input()) + +q = Queue() +q.put([J]) + +output = 0 + +while not q.empty(): + current = q.get() + + if len(current) == 4: + output += 1 + continue + + for i in range(1,current[-1]): + q.put(current + [i]) + +print(output) diff --git a/Main/Python/2012/__pycache__/S1.cpython-310.pyc b/Main/Python/2012/__pycache__/S1.cpython-310.pyc new file mode 100644 index 0000000..6f947da Binary files /dev/null and b/Main/Python/2012/__pycache__/S1.cpython-310.pyc differ diff --git a/Main/Python/__pycache__/tester.cpython-310.pyc b/Main/Python/__pycache__/tester.cpython-310.pyc new file mode 100644 index 0000000..ac18695 Binary files /dev/null and b/Main/Python/__pycache__/tester.cpython-310.pyc differ diff --git a/Main/Python/grader.py b/Main/Python/grader.py new file mode 100644 index 0000000..a55c775 --- /dev/null +++ b/Main/Python/grader.py @@ -0,0 +1,50 @@ +import io, sys, os, time +from tester import run + + +class Capturing(list): + def __enter__(self): + self._stdout = sys.stdout + sys.stdout = self._stringio = io.StringIO() + return self + + def __exit__(self, *args): + self.extend(self._stringio.getvalue().splitlines()) + del self._stringio # free up some memory + sys.stdout = self._stdout + + +PATH = "2012/" +PROBLEM = "S1" + +test_input_path = os.path.join(PATH, f"windows_data/senior/{PROBLEM}/") + +test_inputs = [] +test_outputs = [] +for root, dirs, files in os.walk(test_input_path): + for i, file in enumerate(files): + with open(os.path.join(root, file), "r") as f: + if i % 2 == 0: + test_inputs.append(f.read()) + else: + test_outputs.append(f.read()) + +total = min(len(test_inputs), len(test_outputs)) +correct = 0 + +for test_input, test_output in zip(test_inputs, test_outputs): + with Capturing() as output: + start = time.perf_counter() + run(PATH, PROBLEM, test_input) + end = time.perf_counter() + + if "\n".join(output) + "\n" == test_output: + print(f"Test Passed. {round(end - start, 3)}s") + correct += 1 + else: + print(f"Test Failed. {round(end - start, 3)}s") + print(f"{test_input = }") + print(f"{test_output = }") + +print("--------------------------------") +print(f"Tests passed: {correct}/{total}") \ No newline at end of file diff --git a/Main/Python/tester.py b/Main/Python/tester.py new file mode 100644 index 0000000..e7c9db0 --- /dev/null +++ b/Main/Python/tester.py @@ -0,0 +1,6 @@ +import sys, io, importlib, os + + +def run(PATH, PROBLEM, test_input): + sys.stdin = io.StringIO(test_input) + exec(open(os.path.join(PATH, PROBLEM + ".py")).read()) diff --git a/Main/__pycache__/test.cpython-310.pyc b/Main/__pycache__/test.cpython-310.pyc new file mode 100644 index 0000000..5bec488 Binary files /dev/null and b/Main/__pycache__/test.cpython-310.pyc differ diff --git a/Main/__pycache__/test2.cpython-310.pyc b/Main/__pycache__/test2.cpython-310.pyc new file mode 100644 index 0000000..54082a8 Binary files /dev/null and b/Main/__pycache__/test2.cpython-310.pyc differ diff --git a/Main/test.py b/Main/test.py index ffaa416..7b0b575 100644 --- a/Main/test.py +++ b/Main/test.py @@ -1,5 +1,31 @@ -test = {1:0,2:1,3:-1} -print(max(test.values())) +import io, sys, os +import importlib + +class Capturing(list): + def __enter__(self): + self._stdout = sys.stdout + sys.stdout = self._stringio = io.StringIO() + return self + def __exit__(self, *args): + self.extend(self._stringio.getvalue().splitlines()) + del self._stringio # free up some memory + sys.stdout = self._stdout + + +filename = "test2.py" +# file = + + +for i in range(3): + with Capturing() as output: + x = os.system(filename) + + print("\n".join(output), type(output)) + print("a") + + +# test = {1:0,2:1,3:-1} +# print(max(test.values())) # test = {1,2,3} diff --git a/Main/test2.py b/Main/test2.py new file mode 100644 index 0000000..b0fc313 --- /dev/null +++ b/Main/test2.py @@ -0,0 +1,2 @@ +output = 0 +print(output) \ No newline at end of file