if the user submitted solution is shit wrong then fucking dont add to the shit database.
also removed unnccessary fucking function
This commit is contained in:
@@ -85,7 +85,6 @@ def view_problem(folder):
|
||||
'test_code': row[2], # now correct
|
||||
}
|
||||
|
||||
|
||||
result = None
|
||||
if request.method == 'POST':
|
||||
user_code = request.form['user_code']
|
||||
@@ -96,6 +95,7 @@ def view_problem(folder):
|
||||
current, peak = tracemalloc.get_traced_memory()
|
||||
tracemalloc.stop()
|
||||
memory_used = peak // 1024 # in KB
|
||||
|
||||
# Try to get the last line number executed (even for successful runs)
|
||||
line_number = None
|
||||
try:
|
||||
@@ -109,6 +109,7 @@ def view_problem(folder):
|
||||
line_number = get_max_lineno(tree)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# If there was an error, try to get the error line number from the traceback
|
||||
if run_result['error']:
|
||||
tb = run_result['error']
|
||||
@@ -119,7 +120,11 @@ def view_problem(folder):
|
||||
line_number = tb_lines[-1].lineno
|
||||
except Exception:
|
||||
pass
|
||||
log_leaderboard(username, problem['folder'], run_result['runtime'], memory_used, line_number)
|
||||
|
||||
# ONLY log to leaderboard if the solution passed all tests
|
||||
if run_result['passed']:
|
||||
log_leaderboard(username, problem['folder'], run_result['runtime'], memory_used, line_number)
|
||||
|
||||
result = run_result
|
||||
return render_template('problem.html', problem=problem, result=result)
|
||||
|
||||
|
||||
@@ -5,28 +5,6 @@ import time
|
||||
from models import db, Problem
|
||||
from flask import current_app
|
||||
|
||||
def load_problems_from_json(json_path):
|
||||
if not os.path.exists(json_path):
|
||||
print(f"Problem JSON file not found: {json_path}")
|
||||
return
|
||||
with open(json_path, 'r') as f:
|
||||
problems = json.load(f)
|
||||
for p in problems:
|
||||
# Check if problem already exists by title
|
||||
existing = Problem.query.filter_by(title=p['title']).first()
|
||||
# Load test code from solution file if provided
|
||||
test_code = ''
|
||||
if 'solution' in p and os.path.exists(p['solution']):
|
||||
with open(p['solution'], 'r') as sf:
|
||||
test_code = sf.read()
|
||||
if existing:
|
||||
existing.description = p['description']
|
||||
existing.test_code = test_code
|
||||
else:
|
||||
new_problem = Problem(title=p['title'], description=p['description'], test_code=test_code)
|
||||
db.session.add(new_problem)
|
||||
db.session.commit()
|
||||
|
||||
def schedule_problem_reload(app, json_path, interval_hours=10):
|
||||
def reload_loop():
|
||||
while True:
|
||||
|
||||
44
src/problems/ReversedList/description.md
Normal file
44
src/problems/ReversedList/description.md
Normal file
@@ -0,0 +1,44 @@
|
||||
## Reverse a List
|
||||
|
||||
Write a function called `reverse_list` that takes a list as input and returns the list in reverse order.
|
||||
You are **not allowed** to just use Python’s built-in `.reverse()` method or slicing (`[::-1]`) — try to reverse it manually for practice.
|
||||
|
||||
### Function Signature:
|
||||
|
||||
```python
|
||||
def reverse_list(lst):
|
||||
# your code here
|
||||
```
|
||||
|
||||
### Requirements
|
||||
|
||||
* The function should return a new list with the elements in reversed order.
|
||||
* The input list can contain:
|
||||
|
||||
* Numbers
|
||||
* Strings
|
||||
* Booleans
|
||||
* A mix of different types
|
||||
* Your function will be tested with:
|
||||
|
||||
* A small list (e.g., `[1, 2, 3]` → `[3, 2, 1]`)
|
||||
* A longer list (e.g., `[1, 2, 3, 4]` → `[4, 3, 2, 1]`)
|
||||
* An empty list (should return an empty list)
|
||||
* A single-element list (should return the same list)
|
||||
* A mixed-type list (e.g., `[1, 'a', True]` → `[True, 'a', 1]`)
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
reverse_list([1, 2, 3])
|
||||
# Output: [3, 2, 1]
|
||||
|
||||
reverse_list([])
|
||||
# Output: []
|
||||
|
||||
reverse_list([5])
|
||||
# Output: [5]
|
||||
|
||||
reverse_list([1, 'a', True])
|
||||
# Output: [True, 'a', 1]
|
||||
```
|
||||
7
src/problems/ReversedList/manifest.json
Normal file
7
src/problems/ReversedList/manifest.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"title": "Reversed List",
|
||||
"description": "Given a list, return a new list with the elements in reverse order.",
|
||||
"description_md": "problems/reversedlist/description.md",
|
||||
"difficulty": "easy",
|
||||
"test_code": "problems/reversedlist/test.py"
|
||||
}
|
||||
27
src/problems/ReversedList/test.py
Normal file
27
src/problems/ReversedList/test.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import unittest
|
||||
|
||||
#def reverse_list(lst : list) -> list:
|
||||
#return lst[::-1]
|
||||
|
||||
class TestSolution(unittest.TestCase):
|
||||
def test_simple(self):
|
||||
test_cases = [
|
||||
([1, 2, 3], [3, 2, 1]), # Simple case
|
||||
([1, 2, 3, 4], [4, 3, 2, 1]), # Longer list
|
||||
([], []), # Empty list
|
||||
([5], [5]), # Single element list
|
||||
([1, 'a', True], [True, 'a', 1]) # Mixed types
|
||||
]
|
||||
print("\n FUNCTION OUTPUT TEST RESULTS")
|
||||
|
||||
for input_val , expected in test_cases:
|
||||
try:
|
||||
actual = reverse_list(input_val) # pyright: ignore[reportUndefinedVariable]
|
||||
status = "✓ PASS" if actual == expected else "✗ FAIL"
|
||||
print(f"{status} | Input: {input_val} -> Got: {actual} | Expected: {expected}")
|
||||
self.assertEqual(actual, expected)
|
||||
except Exception as e:
|
||||
print(f"✗ ERROR | Input: {input_val} -> Exception: {e}")
|
||||
raise
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
Reference in New Issue
Block a user