Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions example_tasks/from_alhawraa/multiplication_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Multiplication table utility for from_alhawraa."""

from __future__ import annotations


def get_int_input(prompt: str, min_value: int | None = None) -> int:
while True:
raw_value = input(prompt).strip()
if not raw_value:
print("Input cannot be empty. Please enter a number.")
continue

if not raw_value.lstrip("+-").isdigit():
print("Please enter a valid integer.")
continue

value = int(raw_value)
if min_value is not None and value < min_value:
print(f"Please enter a number greater than or equal to {min_value}.")
continue

return value


def format_multiplication_table(number: int, limit: int) -> list[str]:
return [f"{number} x {i} = {number * i}" for i in range(1, limit + 1)]


def main() -> None:
print("=== Multiplication Table Utility ===")
number = get_int_input("Enter the number: ")
limit = get_int_input("Enter the limit: ", min_value=1)

print("\nResult:")
for line in format_multiplication_table(number, limit):
print(line)


if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ async def post_feedback(request: fastapi.Request):

if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
uvicorn.run(app, host="0.0.0.0", port=8000)

88 changes: 77 additions & 11 deletions project_enigma/decoding_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,82 @@
def decode_measurements(encoded_string: str) -> list[int]:
"""This function decodes an encoded string into a list of integers.
RULE 1: A generic logic should be implemented without handling edge cases using if statements for specific inputs.
RULE 2: The generic logic should handle all inputs and generate the expected outputs.
"""This function decodes an encoded string into a list of integers."""
results = []
i = 0
n = len(encoded_string)

Args:
encoded_string (str): The encoded string to decode.
def read_value_token():
nonlocal i
if i >= n or encoded_string[i] == ' ':
return None
c = encoded_string[i]
if c == '_':
i += 1
return 0
val = 0
while i < n:
ch = encoded_string[i]
if ch == 'z':
val += 26
i += 1
elif ch == '_':
i += 1
return val
elif ch == ' ':
return val
else:
val += ord(ch) - ord('a') + 1
i += 1
return val
return val

Returns:
list[int]: The list of decoded integers.
"""
pass # Remove this pass and place your logic here to decode the string into a list of integers based on the specified encoding rules.
return [] # Placeholder return statement; replace with actual decoding logic.
while i < n:
c = encoded_string[i]

if c == ' ':
i += 1
continue

if c == '_':
while i < n and encoded_string[i] != ' ':
i += 1
results.append(0)
continue

count = 0
zero_cycle = False
while i < n:
ch = encoded_string[i]
if ch == ' ':
break
if ch == '_':
while i < n and encoded_string[i] != ' ':
i += 1
results.append(0)
zero_cycle = True
break
if ch == 'z':
count += 26
i += 1
else:
count += ord(ch) - ord('a') + 1
i += 1
break

if zero_cycle:
continue

total = 0
for _ in range(count):
if i >= n or encoded_string[i] == ' ':
break
val = read_value_token()
if val is None:
break
total += val

results.append(total)

return results


if __name__ == "__main__":
Expand All @@ -37,4 +103,4 @@ def decode_measurements(encoded_string: str) -> list[int]:
for encoded, expected in test_cases:
result = decode_measurements(encoded)
status = "PASS" if result == expected else "FAIL"
print(f"{status}: decode_measurements({encoded!r}) = {result} (expected {expected})")
print(f"{status}: decode_measurements({encoded!r}) = {result} (expected {expected})")