// Numbas version: finer_feedback_settings {"name": "Hamming square code", "extensions": ["codewords"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {}, "ungrouped_variables": ["received_string", "errors", "decoded_words", "decoded_string", "received_words", "error_messages", "show_words", "words", "encwords", "num_words"], "name": "Hamming square code", "tags": [], "type": "question", "advice": "

Since we are using the Hamming square code, each code word is of length $9$. The message we received was $18$ bits long, 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

We put this into the standard form for checking the square code - the received word is written in a $3 \\times 3$ grid, formed of the original word in the top-left $2 \\times 2$ square, with row and column sums on the sides.

\n

\\[\\begin{array}{rr|c}\\var{received_words[0][0]}&\\var{received_words[0][1]}&\\var{received_words[0][2]}\\\\\\var{received_words[0][3]}&\\var{received_words[0][4]}&\\var{received_words[0][5]}\\\\ \\hline \\var{received_words[0][6]}&\\var{received_words[0][7]}&\\var{received_words[0][8]}\\end{array}\\]

\n

{error_messages[errors[0]]}

\n

We know that at most one error has occurred, so the decoded word is $\\var{decoded_words[0]}$.

\n

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

\n

As above, we put this into the standard form for checking the square code:

\n

We put this into the standard form for checking the square code - the received word is written in a $3 \\times 3$ grid, formed of the original word in the top-left $2 \\times 2$ square, with row and column sums on the sides.

\n

\\[\\begin{array}{rr|c}\\var{received_words[1][0]}&\\var{received_words[1][1]}&\\var{received_words[1][2]}\\\\\\var{received_words[1][3]}&\\var{received_words[1][4]}&\\var{received_words[1][5]}\\\\ \\hline \\var{received_words[1][6]}&\\var{received_words[1][7]}&\\var{received_words[1][8]}\\end{array}\\]

\n

{error_messages[errors[1]]}

\n

We know that at most one error has occurred, so the decoded word is $\\var{decoded_words[1]}$.

\n

Putting the decoded words together, the decoded string is $\\var{latex(decoded_string)}$

", "rulesets": {}, "parts": [{"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.

", "marks": 1, "showCorrectAnswer": true, "displayAnswer": "{decoded_string}", "scripts": {}, "answer": "{decoded_string}", "type": "patternmatch"}], "statement": "

A binary string was encoded using Hamming's square code and then transmitted.

\n

The string $\\var{latex(received_string)}$ was received.

", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "preamble": {"css": "", "js": ""}, "variables": {"received_string": {"definition": "join(received_words,'')", "templateType": "anything", "group": "Ungrouped variables", "name": "received_string", "description": ""}, "errors": {"definition": "repeat(random(0..8),num_words)", "templateType": "anything", "group": "Ungrouped variables", "name": "errors", "description": ""}, "num_words": {"definition": "2", "templateType": "number", "group": "Ungrouped variables", "name": "num_words", "description": ""}, "decoded_words": {"definition": "map(hamming_square_decode(word),word,received_words)", "templateType": "anything", "group": "Ungrouped variables", "name": "decoded_words", "description": ""}, "decoded_string": {"definition": "join(decoded_words,'')", "templateType": "anything", "group": "Ungrouped variables", "name": "decoded_string", "description": ""}, "received_words": {"definition": "map(make_error(encwords[j],errors[j]),j,0..num_words-1)", "templateType": "anything", "group": "Ungrouped variables", "name": "received_words", "description": ""}, "error_messages": {"definition": "[ \"The check digits of the first row and first column are wrong, so we change the value in that row and column.\", \"The check digits of the first row and second column are wrong, so we change the value in that row and column.\", \"The check digit of the first row is wrong, but everything else is correct so we assume the error was in the check digit and change nothing.\", \"The check digits of the second row and first column are wrong, so we change the value in that row and column.\", \"The check digits of the second row and second column are wrong, so we change the value in that row and column.\", \"The check digit of the second row is wrong, but everything else is correct so we assume the error was in the check digit and change nothing.\", \"The check digit of the first column is wrong, but everything else is correct so we assume the error was in the check digit and change nothing.\", \"The check digit of the second column is wrong, but everything else is correct so we assume the error was in the check digit and change nothing.\", \"The total check digit is wrong, but everything else is correct so we assume the error was in the check digit and change nothing.\" ]", "templateType": "list of strings", "group": "Ungrouped variables", "name": "error_messages", "description": ""}, "words": {"definition": "repeat(codeword(repeat(random(0,1),4),2),num_words)", "templateType": "anything", "group": "Ungrouped variables", "name": "words", "description": ""}, "encwords": {"definition": "map(hamming_square_encode(word),word,words)", "templateType": "anything", "group": "Ungrouped variables", "name": "encwords", "description": ""}, "show_words": {"definition": "join(words,'')", "templateType": "anything", "group": "Ungrouped variables", "name": "show_words", "description": ""}}, "metadata": {"notes": "", "description": "", "licence": "Creative Commons Attribution 4.0 International"}, "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}