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
58 changes: 58 additions & 0 deletions project_enigma/assumptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Detective's Log — Hidden Rules

Core Encoding Model

The string encodes a sequence of measurement groups. Each group is:

[count_number] [value_number × count]


count_number — how many value-numbers follow in this group.
The count value-numbers are each decoded and summed to produce one integer in the output list.


Number Encoding

A number is read character by character from a stream:


'z' → add 26 to an accumulator; continue reading (multi-char sequence).
Any non-'z' character → add its alphabetical value (a=1 … y=25, z=26) and stop.
'_' → contributes 0 and terminates accumulation.


This is consistent with the spec note: "terminated with the first non-z character following a sequence of multiple characters." A single non-z character is both the sole contribution and the terminator.

The _ (Underscore) Character

_ behaves differently depending on its position:

As a value (inside a group being summed)

_ = 0. It terminates any preceding z-accumulation and adds nothing. Example: z_ = 26 + 0 = 26.

As a count (first number of a new group)

_ = 0, so count = 0. Special rule: when count is 0, the decoder emits a 0-measurement immediately and abandons the rest of the current segment. This is the only way count = 0 is reachable (no other character encodes 0).

This rule explains:


"_" → [0] — count=0, emit 0, nothing left.
"__" → [0] — count=0, emit 0, second _ is abandoned.
"_ad" → [0] — count=0, emit 0, "ad" abandoned.
"_zzzb" → [0] — count=0, emit 0, "zzzb" abandoned.


Space as a Segment Separator

A space character splits the string into independent segments. Each segment is decoded as a self-contained stream; results are concatenated.


"_ _" → ["_", "_"] → [0] + [0] = [0, 0]
"" → [] (no segments, no output)


Implied Rules Not Stated in the Spec

RuleEvidenceValues within a group are summed (not listed individually)"aa" → [1], not [1, 1]_ in count position aborts the segment"__" → [0], not [0, 0]Space is a segment delimiter"_ _" → [0, 0]If count exceeds remaining chars, missing values default to 0"a_" (count=1, one _ value=0) → [0]Empty string → empty list"" → []
46 changes: 46 additions & 0 deletions project_enigma/clarifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Clarification Questions for Acme Metrics Corp

## Q1 — What does _ mean as a count, exactly?

When _ appears as a group count (value = 0), we emit 0 and discard the rest of the segment.
This means _ad and _zzzb both produce [0], not [0, 4] or [0, 80].

Question: Is this intentional — does a _ count mean "null/empty measurement, ignore remainder of packet"?
Or should the trailing characters be decoded as further groups?

Why it matters: If _ simply means count = 0 (emit 0, continue), then "__" should be [0, 0],
contradicting the test case. The only consistent interpretation is that _ as a count terminates the segment.

---

## Q2 — Is space the only inter-segment separator?

Question:
- Are other whitespace characters (tab, newline) also delimiters?
- Can segments be separated by multiple consecutive spaces?
- Are there any other delimiter characters beyond space?

---

## Q3 — What happens when count exceeds remaining characters?

For a count of 5 but only 2 value-characters remaining, we currently sum what is available and treat missing values as 0.

Question: Should an undersupplied group raise an error, return a partial sum, or silently pad with 0?

---

## Q4 — Are characters outside a-z, _ and space valid?

The spec only defines a-z, _ and space. The current implementation treats any other character as 0.

Question: Should unexpected characters like digits, punctuation or uppercase raise an error or be treated as 0?

---

## Potential Contradiction in the Test Suite

The requirements table lists ("_ad", [0]) and ("_zzzb", [0]), but the Python main block
shows ("ad", [0]) and ("zzzb", [0]) without the leading underscore. These would require different logic.

Request: Please confirm which version is authoritative — the requirements table or the main block.
56 changes: 44 additions & 12 deletions project_enigma/decoding_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
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.

Args:
encoded_string (str): The encoded string to decode.

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.
"""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.

Args:
encoded_string (str): The encoded string to decode.

Returns:
list[int]: The list of decoded integers.
"""
def char_value(c: str) -> int:
if c == '_':
return 0
if 'a' <= c <= 'z':
return ord(c) - ord('a') + 1
return 0

def read_number(seg: str, pos: int) -> tuple[int, int]:
acc = 0
while pos < len(seg) and seg[pos] == 'z':
acc += 26
pos += 1
if pos < len(seg):
acc += char_value(seg[pos])
pos += 1
return acc, pos

results: list[int] = []

for seg in encoded_string.split(' '):
pos = 0
while pos < len(seg):
count, pos = read_number(seg, pos)
if count == 0:
results.append(0)
break
total = 0
for _ in range(count):
if pos < len(seg):
val, pos = read_number(seg, pos)
total += val
results.append(total)

return results


if __name__ == "__main__":
Expand Down