// Numbas version: finer_feedback_settings {"name": "Hamming's square code ", "extensions": ["codewords", "permutations"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"parts": [{"customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "prompt": "

Assuming that the received message contains at most one error per codeword, correct any errors, and then decode to find the original binary string.

\n

Original message: [[0]]

\n

", "unitTests": [], "sortAnswers": false, "scripts": {}, "gaps": [{"answer": "\\s*{string(original)}\\s*", "displayAnswer": "{string(original)}", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {}, "type": "patternmatch", "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "variableReplacements": [], "marks": "2"}], "type": "gapfill", "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "variableReplacements": [], "marks": 0, "showFeedbackIcon": true}], "variables": {"error_positions": {"templateType": "anything", "group": "Ungrouped variables", "definition": "repeat(random(0..8),num_codewords)", "description": "

Positions of errors in the received (encoded) code words

", "name": "error_positions"}, "received_words": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(\n error(encoded_original_words[j],error_positions[j]),j,0..(num_codewords-1)\n)", "description": "

The received words, with errors applied

", "name": "received_words"}, "original": {"templateType": "anything", "group": "Ungrouped variables", "definition": "concat(original_words)", "description": "

The original message

", "name": "original"}, "received": {"templateType": "anything", "group": "Ungrouped variables", "definition": "concat(received_words)", "description": "

The received message

", "name": "received"}, "encoded_original_words": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(hamming_square_encode(word),word,original_words)", "description": "

The original words, encoded using the square code

", "name": "encoded_original_words"}, "num_codewords": {"templateType": "number", "group": "Ungrouped variables", "definition": "2", "description": "

Number of words in the message

", "name": "num_codewords"}, "original_words": {"templateType": "anything", "group": "Ungrouped variables", "definition": "shuffle(allwords(4,2) except codeword(\"0000\",2))[0..num_codewords]", "description": "

Randomly chosen distinct codewords, except 0000

", "name": "original_words"}}, "ungrouped_variables": ["num_codewords", "original_words", "encoded_original_words", "error_positions", "received_words", "original", "received"], "preamble": {"css": "", "js": ""}, "name": "Hamming's square code ", "variable_groups": [], "functions": {"error_description": {"type": "string", "language": "javascript", "definition": "var ordinals = [\"first\",\"second\"];\nvar digits = word.digits.slice();\nvar sentences = [];\n\nvar n = 3;\n\nvar row_error;\nvar column_error;\nfor(var i=0;iA binary string was encoded using Hamming's square code, and then transmitted.

\n

The string $\\var{received}$ was received. 

", "tags": [], "rulesets": {}, "extensions": ["codewords", "permutations"], "type": "question", "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

Correct an error in a received message which was encoded using Hamming's square code

"}, "advice": "

Since we are using the Hamming square code, each encoded code word is of length $9$. We received $18$ digits, so we have $2$ words to check and decode, $\\var{received_words[0]}$ and $\\var{received_words[1]}$. 

\n

Checking the received word $\\var{received_words[0]}$

\n

Put this word into a square array.

\n

{check_array(received_words[0])}

\n

Since we know that at most one error has occurred we can decode as follows:

\n

{error_description(received_words[0])}

\n

Checking the received word $\\var{received_words[1]}$

\n

Put this word into a square array.

\n

{check_array(received_words[1])}

\n

Since we know that at most one error has occurred we can decode as follows:

\n

{error_description(received_words[1])}

\n

Putting these decoded messages together, we obtain $\\var{original}$ as the answer.

", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/3/"}, {"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/3/"}, {"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}