new problem and i added better support for sorting and a overall better script
This commit is contained in:
17
src/app.py
17
src/app.py
@@ -1,5 +1,6 @@
|
|||||||
|
# API endpoint to get problem manifest (description) by folder
|
||||||
from markupsafe import Markup
|
from markupsafe import Markup
|
||||||
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
|
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, jsonify
|
||||||
import markdown as md
|
import markdown as md
|
||||||
import ast
|
import ast
|
||||||
from src.models import db, Problem, Solution
|
from src.models import db, Problem, Solution
|
||||||
@@ -30,6 +31,20 @@ def setup():
|
|||||||
# Start the background thread to scan problems
|
# Start the background thread to scan problems
|
||||||
start_problem_scanner()
|
start_problem_scanner()
|
||||||
|
|
||||||
|
@app.route('/api/problem_manifest/<folder>')
|
||||||
|
def api_problem_manifest(folder):
|
||||||
|
# Try to load manifest.json from the problem folder
|
||||||
|
import json
|
||||||
|
manifest_path = BASE_DIR / 'problems' / folder / 'manifest.json'
|
||||||
|
if not manifest_path.exists():
|
||||||
|
return jsonify({'error': 'Manifest not found'}), 404
|
||||||
|
try:
|
||||||
|
with open(manifest_path, 'r', encoding='utf-8') as f:
|
||||||
|
manifest = json.load(f)
|
||||||
|
return jsonify(manifest)
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
@app.route("/script.js")
|
@app.route("/script.js")
|
||||||
def script():
|
def script():
|
||||||
return send_from_directory("templates", "script.js")
|
return send_from_directory("templates", "script.js")
|
||||||
|
|||||||
90
src/problems/PrimeNumber/description.md
Normal file
90
src/problems/PrimeNumber/description.md
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
# Prime Number Function Checker
|
||||||
|
|
||||||
|
You are asked to **write a function** that checks if a number is a **prime number**.
|
||||||
|
|
||||||
|
### What is a Prime Number?
|
||||||
|
|
||||||
|
* A **prime number** is a whole number greater than `1`.
|
||||||
|
* It has only **two divisors**: `1` and the number itself.
|
||||||
|
* Example:
|
||||||
|
|
||||||
|
* `7` → Prime (divisible only by `1` and `7`)
|
||||||
|
* `8` → Not Prime (divisible by `1, 2, 4, 8`)
|
||||||
|
|
||||||
|
Numbers less than or equal to `1` are **not prime**.
|
||||||
|
|
||||||
|
📖 More info: [Wikipedia](https://en.wikipedia.org/wiki/Prime_number)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Function Signature
|
||||||
|
|
||||||
|
```python
|
||||||
|
def check_prime(number: int) -> bool:
|
||||||
|
```
|
||||||
|
|
||||||
|
* **Input**:
|
||||||
|
|
||||||
|
* `number` → an integer
|
||||||
|
|
||||||
|
* **Output**:
|
||||||
|
|
||||||
|
* `True` → if the number is prime
|
||||||
|
* `False` → if the number is not prime
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Example 1
|
||||||
|
|
||||||
|
**Input:**
|
||||||
|
|
||||||
|
```python
|
||||||
|
check_prime(2)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Output:**
|
||||||
|
|
||||||
|
```
|
||||||
|
True
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Example 2
|
||||||
|
|
||||||
|
**Input:**
|
||||||
|
|
||||||
|
```python
|
||||||
|
check_prime(4)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Output:**
|
||||||
|
|
||||||
|
```
|
||||||
|
False
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Example 3
|
||||||
|
|
||||||
|
**Input:**
|
||||||
|
|
||||||
|
```python
|
||||||
|
check_prime(13)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Output:**
|
||||||
|
|
||||||
|
```
|
||||||
|
True
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**_Dont worry you do NOT need to write these Function Calls into your solution. QPP checks automatically_**
|
||||||
|
|
||||||
|
### Hint
|
||||||
|
|
||||||
|
Try using the **modulo operator `%`** to check if one number divides evenly into another.
|
||||||
|
If any number between `2` and `n-1` divides your number evenly, then it’s **not prime**.
|
||||||
7
src/problems/PrimeNumber/manifest.json
Normal file
7
src/problems/PrimeNumber/manifest.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"title": "Prime Number Checker",
|
||||||
|
"description": "Determine if a given number is a prime number",
|
||||||
|
"description_md": "problems/PrimeNumber/description.md",
|
||||||
|
"test_code": "problems/PrimeNumber/test.py",
|
||||||
|
"difficulty": "medium"
|
||||||
|
}
|
||||||
33
src/problems/PrimeNumber/test.py
Normal file
33
src/problems/PrimeNumber/test.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
# <!-- Function to check -->
|
||||||
|
# def check_prime(number : int) -> bool:
|
||||||
|
# for i in range(2, int(number)):
|
||||||
|
# if int(number) % i == 0:
|
||||||
|
# return False
|
||||||
|
# return True
|
||||||
|
|
||||||
|
class TestPrimeNumber(unittest.TestCase):
|
||||||
|
def test_prime_function(self):
|
||||||
|
test_cases = [
|
||||||
|
(2,True),
|
||||||
|
(3,True),
|
||||||
|
(4,False),
|
||||||
|
(6,False),
|
||||||
|
(1,False)
|
||||||
|
]
|
||||||
|
print("\nFUNCTION OUTPUT TEST RESULTS")
|
||||||
|
|
||||||
|
for input_val, expected in test_cases:
|
||||||
|
try:
|
||||||
|
actual = check_prime(input_val)
|
||||||
|
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)
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
## Reverse a List
|
## Reverse a List
|
||||||
|
|
||||||
Write a function called `reverse_list` that takes a list as input and returns the list in reverse order.
|
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.
|
You are **allowed** to just use Python’s built-in `.reverse()` method or slicing (`[::-1]`), try to reverse it manually for practice.
|
||||||
|
|
||||||
### Function Signature:
|
### Function Signature:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def reverse_list(lst):
|
def reverse_list(lst):
|
||||||
# your code here
|
# your code here
|
||||||
```
|
```
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 9.4 KiB |
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user