Rare for basic CodeHS, but brilliant students try Huffman-style encoding: assign shorter codes to frequent letters (e, t, a) and longer codes to rare letters (z, q).
Example mapping:
e → 0
t → 10
a → 110
space → 1110
etc. 8.3 8 create your own encoding codehs answers
Insight: This introduces compression theory – the most interesting computer science concept in the exercise, though often beyond the official rubric. Rare for basic CodeHS, but brilliant students try
Your “custom” element is the rule. In this case, adding 5 modifies the standard ASCII mapping. A message like "Hi" becomes [77, 110] instead of [72, 105]. Decoding rule: Read encoded string in two-digit blocks;
When solving 8.3.8, students often run into these issues:
| Mistake | Why It Happens | Fix |
|---------|----------------|-----|
| Forgetting to handle spaces | Space (' ') has ASCII 32. After shift, it becomes 37, which is '%'. Your decode must reverse correctly. | Test with "a b" to ensure spaces survive round-trip. |
| Using a non-reversible rule | Example: multiplying by 2. Two different chars (like 'a'=97 and 'b'=98) could map to same number after mod. | Always use a bijective (one-to-one) rule. Addition/subtraction works perfectly. |
| Returning a string instead of list | The prompt explicitly asks for a list of integers. | Use encoded_list.append(...) and return the list. |