diff --git a/.github/workflows/test_codex9.yml b/.github/workflows/test_codex9.yml index 236bf3e..7c43fd2 100644 --- a/.github/workflows/test_codex9.yml +++ b/.github/workflows/test_codex9.yml @@ -28,4 +28,4 @@ jobs: - name: Run Codex9 Tests run: | echo "πŸ” Running unit tests..." - pytest -q test_codex9.py + pytest -q miniproject-1-codex9-ilysimo/test_codex9.py diff --git a/miniproject-1-codex9/INSTRUCTIONS.md b/miniproject-1-codex9-cpp/INSTRUCTIONS.md similarity index 100% rename from miniproject-1-codex9/INSTRUCTIONS.md rename to miniproject-1-codex9-cpp/INSTRUCTIONS.md diff --git a/miniproject-1-codex9/codex9.py b/miniproject-1-codex9-cpp/codex9.py similarity index 84% rename from miniproject-1-codex9/codex9.py rename to miniproject-1-codex9-cpp/codex9.py index e4ec85c..efe39d1 100644 --- a/miniproject-1-codex9/codex9.py +++ b/miniproject-1-codex9-cpp/codex9.py @@ -3,8 +3,8 @@ 🧩 Mini Project: The Data Heist of Codex-9 ========================================================= -TEAM: # Your team's name -MEMBERS: # List of team members +TEAM: # C++ +MEMBERS: # 24101010, 24071004 STORY: The AI system Codex-9 has been hacked. Fragments of its digital blueprint @@ -54,7 +54,15 @@ def decode_fragment(fragment: str) -> list: ['code', 'python', 'Data', 'structure', 'Algorithms'] """ # TODO: Implement the decoding logic here - pass + if not fragment: + return [] + + parts = fragment.split(";") + + decoded = [p[::-1] for p in parts if p] + + return decoded + # ======================================================= @@ -77,9 +85,9 @@ def organize_segments(words: list, module_numbers: list) -> list: Example Output: [('code', 104), ('python', 215), ('Data', 309), ('structure', 412), ('Algorithms', 518)] """ - # TODO: Combine words and IDs into tuples - pass - + if len(words) != len(module_numbers): + raise ValueError(f"Length mismatch") + return list(zip(words, module_numbers)) # ======================================================= # 🧩 TASK 3 β€” Verify Module Uniqueness (Sets) @@ -100,7 +108,7 @@ def unique_modules(modules: list) -> list: [('code', 104), ('python', 215)] """ # TODO: Convert to set and back to list - pass + return list(set(modules)) # ======================================================= @@ -123,8 +131,13 @@ def build_restoration_queue(unique_list: list) -> list: [104, 215, 309] """ # TODO: Use deque for queue logic - pass + q = deque() + for _, module_id in unique_list: + q.append(module_id) + return [q.popleft() for _ in range(len(q))] + + # ======================================================= # 🧩 TASK 5 β€” Track Actions with Stack (Stack) # ======================================================= @@ -147,7 +160,18 @@ def track_actions(module_ids: list) -> list: ['load_104', 'verify_215'] """ # TODO: Use list as stack and pop last 3 - pass + stack = [] + for i, mid in enumerate(module_ids): + if i % 2 == 0: + stack.append(f"load_{mid}") + else: + stack.append(f"verify_{mid}") + + if len(stack) > 3: + stack = stack[:-3] + else: + stack = [] + return stack # ======================================================= @@ -177,7 +201,11 @@ def map_actions_to_metadata(actions: list, metadata: dict) -> dict: } """ # TODO: Extract module IDs from actions and map metadata - pass + result = {} + for a in actions: + mid = int(a.split("_")[1]) + result[a] = metadata[mid] + return result # ======================================================= @@ -199,7 +227,14 @@ def quick_sort_modules(modules: list) -> list: [(309, 2.1), (104, 3.4), (215, 5.2)] """ # TODO: Implement quick sort - pass + if len(modules) <= 1: + return modules + + pivot = modules[0] + left = [x for x in modules[1:] if x[1] <= pivot[1]] + right = [x for x in modules[1:] if x[1] > pivot[1]] + + return quick_sort_modules(left) + [pivot] + quick_sort_modules(right) # ======================================================= @@ -231,7 +266,13 @@ def insert_bst(root: BSTNode, key: int, value: float) -> BSTNode: value (float): The module size. """ # TODO: Insert node correctly - pass + if root is None: + return BSTNode(key, value) + if value < root.value: + root.left = insert_bst(root.left, key, value) + else: + root.right = insert_bst(root.right, key, value) + return root def inorder_bst(root: BSTNode) -> list: """ @@ -241,7 +282,9 @@ def inorder_bst(root: BSTNode) -> list: root (BSTNode): The root of the BST. """ # TODO: Implement inorder traversal - pass + if root is None: + return [] + return inorder_bst(root.left) + [(root.key, root.value)] + inorder_bst(root.right) @@ -269,7 +312,7 @@ def build_dependency_graph(connection_map: dict) -> dict: Same dictionary (adjacency list) """ # TODO: Return adjacency list - pass + return connection_map # ======================================================= @@ -301,6 +344,15 @@ def dfs_activation(graph: dict, start: str) -> list: System Message: Blueprint successfully restored. Codex-9 reboot complete. """ # TODO: Implement recursive DFS - pass + visited = [] + + def dfs(node): + if node in visited: + return + visited.append(node) + for nxt in graph[node]: + dfs(nxt) + dfs(start) + return visited, "Blueprint successfully restored. Codex-9 reboot complete." diff --git a/miniproject-1-codex9/test_codex9.py b/miniproject-1-codex9-cpp/test_codex9.py similarity index 100% rename from miniproject-1-codex9/test_codex9.py rename to miniproject-1-codex9-cpp/test_codex9.py diff --git a/miniproject-2-protocol-QV-7/INSTRUCTIONS.md b/miniproject-2-protocol-QV-7/INSTRUCTIONS.md new file mode 100644 index 0000000..7f6fa07 --- /dev/null +++ b/miniproject-2-protocol-QV-7/INSTRUCTIONS.md @@ -0,0 +1,210 @@ +### 🧠 Storyline + +Deep beneath the abandoned research complex Helion Prime, a classified experimental containment system known as the Quantum Vault has suffered a catastrophic breach. + +Inside the Vault lie encrypted algorithmic artifacts β€” predictive AIs, mathematical models, temporal distortion engines β€” all stored as quantum shards. +When the breach occurred, these shards were fragmented, scrambled, and scattered across corrupted memory sectors. + +The Quantum Recovery Task Unit (you) has been activated. + +### 🧠 Project Overview + +* Number of tasks: 10 +* Recommended team size: 1–4 students +* Topics covered: +Strings, lists, sets, tuples, stacks, queues, dictionaries, searching/sorting algorithms, binary search trees, graphs +* Final goal: Rebuild the Quantum Lattice Map and secure The Vault. + +### βš™οΈ TASKS + +#### Task 1 β€” Extract Quantum Shards + +You are given a corrupted quantum data stream where shards are separated by #. + +``` +"23noitazimitpO#gnirts_001#eman-tceles" +``` + +You must: +* Split the string into fragments +* Reverse each fragment +* Remove all characters except letters, digits, and hyphens +* Return the resulting cleaned list + +```py +['Optimization32', '100_string', 'select-name'] +``` + + +#### Task 2 β€” Pair Shards with Sequence Codes + +You receive a list of decoded shard strings and a list of integer sequence codes. + +You must pair them into tuples: + +```py +(shard_string, code) +``` + +```py +shards = ['alpha', 'beta', 'gamma', 'alpha'] +codes = [7, 12, 18, 22] +``` + +```py +[('alpha', 7), ('beta', 12), ('gamma', 18), ('alpha', 22)] +``` + + +#### TASK 3 β€” Stabilize Shard Registry + +Duplicates may exist due to memory corruption. + +You must: +* Convert the list of shard tuples to a set +* Convert it back to a list +* Return only unique shard entries + +```py +[('alpha', 7), ('beta', 12), ('gamma', 18), ('alpha', 22)] +``` + +```py +[('alpha', 7), ('beta', 12), ('gamma', 18)] +``` + +#### Task 4 β€” Initialize Reconstruction Queue + +Processing must occur in the exact order that unique shard pairs appear. + +```py +[('alpha', 7), ('beta', 12), ('gamma', 18)] +``` + +You must: +* Create a FIFO queue (collections.deque) +* Enqueue each (shard, code) tuple +* Dequeue items one by one +* Return a list only of the sequence codes in processed order + +```py +[7, 12, 18] +``` + +#### TASK 5 β€” Action Log Stack + +For each code, generate two actions: +* `decode_` +* `validate_` + + +```py +[7, 12, 18] +``` + + +```py +['decode_7', 'validate_7', 'decode_12', 'validate_12', 'decode_18', 'validate_18'] +# after removing 2: +['decode_7', 'validate_7', 'decode_12', 'validate_12'] +``` + +#### TASK 6 β€” Annotate Shards + +You must: +* Use each action name (e.g., "decode_7") +* Extract the code (e.g., 7) +* Map the action to metadata found in shard_info[code] + +```py +actions = ['decode_7'] +shard_info = {7: {"energy": 1.2, "state": "stable"}, + 12: {"energy": 2.5, "state": "unstable"}, + 18: {"energy": 3.1, "state": "stable"}, + 22: {"energy": 4.0, "state": "critical"}, + 2: {"energy": 0.9, "state": "stable"}} +``` + + +```py +{'decode_7': {'energy': 1.2, 'state': 'stable'}, + 'validate_7': {'energy': 1.2, 'state': 'stable'}, + 'decode_12': {'energy': 2.5, 'state': 'unstable'}, + 'validate_12': {'energy': 2.5, 'state': 'unstable'}} +``` + + +#### TASK 7 β€” Sort Shards by Energy + +You will receive a list of tuples: + +``` +(code, energy) +``` + +You must: +* Implement a sort algorithm manually(by your choice, e.g., quick sort, merge sort, bubble sort) +* Sort by energy in ascending order +* Return the sorted list + +```py +[(18, 3.1), (7, 1.2), (12, 2.5)] +``` + +```py +[(7, 1.2), (12, 2.5), (18, 3.1)] +``` + + +#### TASK 8 β€” Rebuild Quantum Integrity Tree + +You must implement a Binary Search Tree where: +* The tree is ordered by energy +* Each node stores (code, energy) +* You must implement: + * insert_qv + * inorder_qv + +**Inorder traversal must return items sorted by energy.** + +```py +[(18, 3.1), (2, 0.9), (22, 4.0), (7, 1.2), (12, 2.5)] +``` + +```py +[(2, 0.9), (7, 1.2), (12, 2.5), (18, 3.1), (22, 4.0)] +``` + +#### TASK 9 β€” Build Shard Dependency Map + +You receive a dependency mapping: + +```py +{ + "7": ["12"], + "12": ["18"], + "18": [] +} +``` + +You must return a clean adjacency list (likely identical to input). +Build a Graph representation using a dictionary of lists. + + + +#### TASK 10 β€” Activate Vault Sequence + +Perform a Depth-First Search starting from a given code. + +You must return: +* The activation order (list) +* A final status message + +```py +graph = {"7": ["12"], "12": ["18"], "18": []} +start = "7" +``` + +```py +(['7', '12', '18'], "Quantum Vault fully restored. Protocol QV-7 complete.") +``` diff --git a/miniproject-2-protocol-QV-7/protocol_qv7.py b/miniproject-2-protocol-QV-7/protocol_qv7.py new file mode 100644 index 0000000..e2f8b6a --- /dev/null +++ b/miniproject-2-protocol-QV-7/protocol_qv7.py @@ -0,0 +1,302 @@ +""" +========================================================= + 🧩 Mini Project: The Quantum Vault Breach β€” Protocol QV-7 +========================================================= + +TEAM: # Your team's name +MEMBERS: # List of team members + +STORY: +Deep beneath the abandoned research facility *Helion Prime*, a classified +containment system known as the **Quantum Vault** has been breached. + +Its encrypted artifactsβ€”mathematical models, neural blueprints, and +time-distortion algorithmsβ€”have fragmented into quantum shards scattered +across corrupted memory sectors. + +Your mission as the **Quantum Recovery Task Unit**: +Reconstruct every shard, rebuild the data structures, re-link dependencies, +and stabilize the Vault before the containment field collapses. + +Every function (Task 1–10) represents a stage of the reconstruction protocol. +Output from each task becomes the input for the next one. + +Follow the protocol. Restore the Vault. Prevent total system collapse. + +INSTRUCTIONS: +1. Complete each function according to its docstring. +2. Use only standard Python libraries. Do not import external packages. +3. You may test each function independently. +4. Do not change function names, arguments, or docstrings. +5. Write clean, optimized, well-commented code. +6. When all tasks are completed and unit tests pass, the Vault stabilizes. +7. After finishing: commit β†’ create PR β†’ tests will run automatically. +8. Fix test failures or review comments and update your PR. +9. Only after approval, your code will be merged into the master branch. + +========================================================= +""" + +from collections import deque +import json +import heapq + + +# ======================================================= +# 🧩 TASK 1 β€” Extract Quantum Shards (Strings β†’ List) +# ======================================================= +def extract_shards(corrupted_stream: str) -> list: + """ + Splits a corrupted quantum stream where shards are separated by '#'. + Each shard is reversed and cleaned of non-alphanumeric characters. + + Arguments: + corrupted_stream (str): The raw corrupted shard string. + + Returns: + list: A list of cleaned, decoded shard strings. + + Example Input: + "23noitazimitpO#gnirts_001#eman-tceles" + Example Output: + ['Optimization32', '100_string', 'select-name'] + """ + # TODO: Implement extraction + cleaning + pass + + +# ======================================================= +# 🧩 TASK 2 β€” Pair Shards with Sequence Codes (List β†’ Tuple) +# ======================================================= +def pair_shards(shards: list, codes: list) -> list: + """ + Combines the decoded shard strings with their associated sequence codes + into tuples of the form (shard, code). + + Arguments: + shards (list): List of decoded shard strings. + codes (list): List of integer sequence codes. + + Returns: + list: List of (shard, code) tuples. + + Example: + shards = ['alpha', 'beta', 'gamma', 'alpha'] + codes = [7, 12, 18, 22] + Output: + [('alpha', 7), ('beta', 12), ('gamma', 18), ('alpha', 22)] + """ + # TODO: Combine the two lists into tuples + pass + + +# ======================================================= +# 🧩 TASK 3 β€” Stabilize Shard Registry (Sets) +# ======================================================= +def stabilize_registry(pairs: list) -> list: + """ + Removes duplicate shard entries using a set and returns a list of + unique shard tuples. + + Arguments: + pairs (list): List of (shard, code) tuples that may include duplicates. + + Returns: + list: A list of unique shard tuples. + + Example Input: + [('alpha', 7), ('beta', 12), ('gamma', 18), ('alpha', 22)] + Example Output: + [('alpha', 7), ('beta', 12), ('gamma', 18)] + """ + # TODO: Convert to set then back to list + pass + + +# ======================================================= +# 🧩 TASK 4 β€” Initialize Reconstruction Queue (Queue) +# ======================================================= +def initialize_queue(unique_pairs: list) -> list: + """ + Initializes a FIFO queue using deque and simulates shard processing. + Returns the sequence codes in the order they were handled. + + Arguments: + unique_pairs (list): List of unique (shard, code) tuples. + + Returns: + list: Ordered list of processed sequence codes. + + Example: + [('alpha', 7), ('beta', 12), ('gamma', 18)] + Output: + [7, 12, 18] + """ + # TODO: Use deque to simulate queue operations + pass + + +# ======================================================= +# 🧩 TASK 5 β€” Action Log Stack (Stack) +# ======================================================= +def action_log(codes: list) -> list: + """ + Builds an action log using a LIFO stack where each code generates + 'decode_' and 'validate_' actions. The last two actions + represent corrupted operations and must be removed (undo). + + Arguments: + codes (list): List of sequence codes. + + Returns: + list: Stack after removing the last two invalid operations. + + Example Input: + [7, 12, 18] + Example Generated Actions: + ['decode_7', 'validate_7', 'decode_12', 'validate_12', 'decode_18', 'validate_18'] + after removing 2: + ['decode_7', 'validate_7', 'decode_12', 'validate_12'] + """ + # TODO: Use Python list as stack + pass + + +# ======================================================= +# 🧩 TASK 6 β€” Annotate Shards (Dictionary) +# ======================================================= +def annotate_shards(actions: list, shard_info: dict) -> dict: + """ + Uses the action names (e.g., 'decode_7') to map each action + to its corresponding shard metadata stored in a dictionary. + + Arguments: + actions (list): Action names in the format 'action_code'. + shard_info (dict): Maps integer codes to metadata dictionaries. + + Returns: + dict: Mapping from action name β†’ metadata. + + Example: + actions = ['decode_7'] + shard_info = {7: {"energy": 1.2, "state": "stable"}} + Output: + {'decode_7': {'energy': 1.2, 'state': 'stable'}} + """ + # TODO: Extract code from action name and map + pass + + +# ======================================================= +# 🧩 TASK 7 β€” Sort Shards by Energy (Sorting Algorithm) +# ======================================================= +def merge_sort_energy(shards: list) -> list: + """ + Sorts a list of (code, energy) tuples by energy using merge sort. + + Arguments: + shards (list): List of (code, energy) tuples. + + Returns: + list: Sorted list by ascending energy. + + Example: + [(18, 3.1), (7, 1.2), (12, 2.5)] + Output: + [(7, 1.2), (12, 2.5), (18, 3.1)] + """ + # TODO: Implement merge sort + pass + + +# ======================================================= +# 🧩 TASK 8 β€” Rebuild Quantum Integrity Tree (Binary Search Tree) +# ======================================================= +class QuantumNode: + """A BST node storing code and energy.""" + def __init__(self, code, energy): + self.code = code + self.energy = energy + self.left = None + self.right = None + +def insert_qv(root: QuantumNode, code: int, energy: float) -> QuantumNode: + """ + Inserts (code, energy) into a BST ordered by energy value. + + Arguments: + root (QuantumNode): The root of the BST. + code (int): Sequence code. + energy (float): Energy value. + """ + # TODO: Implement BST insertion logic + pass + + +def inorder_qv(root: QuantumNode) -> list: + """ + Performs an inorder traversal of the Quantum Vault BST. + + Arguments: + root (QuantumNode): BST root. + + Returns: + list: List of (code, energy) tuples sorted by energy. + + Example: + [(18, 3.1), (2, 0.9), (22, 4.0), (7, 1.2), (12, 2.5)] + Output: + [(2, 0.9), (7, 1.2), (12, 2.5), (18, 3.1), (22, 4.0)] + """ + # TODO: Implement inorder traversal + pass + + +# ======================================================= +# 🧩 TASK 9 β€” Build Shard Dependency Map (Graph) +# ======================================================= +def build_shard_graph(mapping: dict) -> dict: + """ + Builds an adjacency list representing quantum shard dependencies. + + Arguments: + mapping (dict): Maps shard codes to a list of dependent codes. + + Returns: + dict: Adjacency list representing the dependency graph. + + Example: + { + "7": ["12"], + "12": ["18"], + "18": [] + } + """ + # TODO: Return adjacency list + pass + + +# ======================================================= +# 🧩 TASK 10 β€” Activate Vault Sequence (DFS Traversal) +# ======================================================= +def dfs_sequence(graph: dict, start: str) -> list: + """ + Performs DFS to determine the activation order of quantum shards. + + Arguments: + graph (dict): Adjacency list of dependencies. + start (str): Starting shard code. + + Returns: + list: Activation order of shard codes. + str: Completion message. + + Example: + graph = {"7": ["12"], "12": ["18"], "18": []} + start = "7" + Output: + ['7', '12', '18'] + "Quantum Vault fully restored. Protocol QV-7 complete." + """ + # TODO: Implement DFS recursively + pass \ No newline at end of file diff --git a/miniproject-2-protocol-QV-7/test_protocolqv7.py b/miniproject-2-protocol-QV-7/test_protocolqv7.py new file mode 100644 index 0000000..e69de29