]> Skullheadx's Git Forge - CCC.git/commitdiff
S1 2012 + grader
authorSkullheadx <704277@pdsb.net>
Wed, 4 Jan 2023 22:40:50 +0000 (17:40 -0500)
committerSkullheadx <704277@pdsb.net>
Wed, 4 Jan 2023 22:40:50 +0000 (17:40 -0500)
.gitignore
Main/Python/2012/S1.py [new file with mode: 0644]
Main/Python/2012/__pycache__/S1.cpython-310.pyc [new file with mode: 0644]
Main/Python/__pycache__/tester.cpython-310.pyc [new file with mode: 0644]
Main/Python/grader.py [new file with mode: 0644]
Main/Python/tester.py [new file with mode: 0644]
Main/__pycache__/test.cpython-310.pyc [new file with mode: 0644]
Main/__pycache__/test2.cpython-310.pyc [new file with mode: 0644]
Main/test.py
Main/test2.py [new file with mode: 0644]

index bc2a419333d387f8de08c480938005fbb327df72..17ada7301218973c6739b1cef4183d5f56c1ab1c 100644 (file)
@@ -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 (file)
index 0000000..2a76b58
--- /dev/null
@@ -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 (file)
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 (file)
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 (file)
index 0000000..a55c775
--- /dev/null
@@ -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 (file)
index 0000000..e7c9db0
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..54082a8
Binary files /dev/null and b/Main/__pycache__/test2.cpython-310.pyc differ
index ffaa416174a93759479a656bdc1ba9e57ba0af3b..7b0b5751c6aad6586028dd13cbfe7285d2fe7ba7 100644 (file)
@@ -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 (file)
index 0000000..b0fc313
--- /dev/null
@@ -0,0 +1,2 @@
+output = 0
+print(output)
\ No newline at end of file