diff --git a/src/problem_loader.py b/src/problem_loader.py deleted file mode 100644 index 5c85a43..0000000 --- a/src/problem_loader.py +++ /dev/null @@ -1,15 +0,0 @@ -import json -import os -import threading -import time -from models import db, Problem -from flask import current_app - -def schedule_problem_reload(app, json_path, interval_hours=10): - def reload_loop(): - while True: - with app.app_context(): - load_problems_from_json(json_path) - time.sleep(interval_hours * 3600) - t = threading.Thread(target=reload_loop, daemon=True) - t.start() diff --git a/src/problems/regex-phone/description.md b/src/problems/regex-phone/description.md new file mode 100644 index 0000000..c98fad1 --- /dev/null +++ b/src/problems/regex-phone/description.md @@ -0,0 +1,58 @@ +# Phone Number Regular Expression Validation + +You are asked to write a function that checks if a given string is a valid phone number. + +A valid phone number must follow this format: + +```python +123-456-7890 +``` + +* It contains **3 digits**, followed by a **dash (-)** +* Then another **3 digits**, followed by a **dash (-)** +* Then exactly **4 digits** + +If the string matches this exact format, return **True**. Otherwise, return **False**. + +--- + +### Example 1 + +```python +Input: "123-456-7890" +Output: True +``` + +### Example 2 + +```python +Input: "1234567890" +Output: False +``` + +### Example 3 + +```python +Input: "abc-def-ghij" +Output: False +``` + +--- + +### Function Signature + +```python +import re + +def is_valid_phone_number(phone_number: str) -> bool: + return bool("Your Solution Here!") +``` + +--- + +### Hint π + +* Use the **`re`** (regular expression) library. +* `\d` means βa digitβ in regex. +* You will need exactly **3 digits**, then a dash, then **3 digits**, another dash, then **4 digits**. +* Anchors `^` (start of string) and `$` (end of string) can help ensure the whole string matches. \ No newline at end of file diff --git a/src/problems/regex-phone/manifest.json b/src/problems/regex-phone/manifest.json new file mode 100644 index 0000000..607c20f --- /dev/null +++ b/src/problems/regex-phone/manifest.json @@ -0,0 +1,7 @@ +{ + "title": "Regex Phonenumber", + "description": "A regex problem to match phone numbers in various formats.", + "description_md": "problems/regex-phone/description.md", + "difficulty": "hard", + "test_code": "problems/regex-phone/test.py" +} \ No newline at end of file diff --git a/src/problems/regex-phone/test.py b/src/problems/regex-phone/test.py new file mode 100644 index 0000000..799e1da --- /dev/null +++ b/src/problems/regex-phone/test.py @@ -0,0 +1,33 @@ +import re +import unittest + +## def is_valid_phone_number(phone_number : str): + ## return bool(re.search(r"^(\d{3}-){2}\d{4}$", phone_number)) + +import unittest + +class TestPhoneNumberRegex(unittest.TestCase): + def test_if_valid(self): + test_cases = [ + ("123-456-7890", True), # Valid format + ("111-222-3333", True), # Another valid format + ("abc-def-ghij", False), # Letters instead of digits + ("1234567890", False), # Missing dashes + ("123-45-67890", False), # Wrong grouping + ("12-3456-7890", False), # Wrong grouping again + ("", False), # Empty string + ] + print("\nPHONE NUMBER VALIDATION TEST RESULTS") + + for phone, expected in test_cases: + try: + actual = is_valid_phone_number(phone) # pyright: ignore[reportUndefinedVariable] + status = "β PASS" if actual == expected else "β FAIL" + print(f"{status} | Input: '{phone}' -> Got: {actual} | Expected: {expected}") + self.assertEqual(actual, expected) + except Exception as e: + print(f"β ERROR | Input: '{phone}' -> Exception: {e}") + raise + +if __name__ == "__main__": + unittest.main(verbosity=2) \ No newline at end of file diff --git a/src/templates/index.html b/src/templates/index.html index b1e7943..14dec25 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -23,6 +23,12 @@ } #rankInfoBtn.active { color: #2563eb; cursor:pointer; transition: transform 0.3s ease; } #rankInfoBtn.active { transform: rotate(90deg); } + +/* Highlight top rank */ +.rank-1 { background-color: #f0fff0; } +.rank-1 td:first-child { font-weight: bold; color: #2e7d32; } +.sort-asc::after { content: " β"; } +.sort-desc::after { content: " β"; }
@@ -86,7 +92,7 @@