// Numbas version: finer_feedback_settings {"name": "Find all codewords with given Hamming distance", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {"random_word": {"definition": "var s = '';\nvar all_digits_same = new RegExp('^(\\\\d)\\\\1{'+(word_length-1)+'}$');\nvar fail;\n\nwhile(fail || s=='') {\n s = '';\n for(var i=0;iThe code words are:

\n

{ball_text}

", "rulesets": {}, "parts": [{"prompt": "

Write down all words $w \\in \\mathbb{Z}^{\\var{word_length}}_{\\var{field_size}}$ for which $d_H(w,\\var{latex(base_word)}) = \\var{distance}$.

\n

Enter your answer as a list of codewords separated by commas, e.g. 0000,1111,...

\n

[[0]]

", "marks": 0, "gaps": [{"marks": "1", "showCorrectAnswer": true, "displayAnswer": "{join(ball,',')}", "scripts": {"validate": {"order": "instead", "script": "// If the student's answer had a syntax error, give them a warning with a hint\nif(this.failSyntax) {\n this.giveWarning('You have not written a valid answer. Your answer should be a list of codewords separated by commas.');\n return false;\n}\n\nreturn true;"}, "mark": {"order": "instead", "script": "var p = this;\nvar field_size = variables.field_size;\nvar word_length = variables.word_length;\nvar base_word = variables.base_word;\nvar desired_distance = variables.distance;\n\nvar number_of_words = variables.number_of_words;\n\nvar studentAnswer = this.cleanAnswer(this.studentAnswer);\n\n// check the student has written a list of codewords separated by commas\nthis.failSyntax = !(/^\\d+(,\\d+)*$/.test(studentAnswer));\nif(this.failSyntax) {\n return;\n}\n\n//split string into individual words\nvar list = studentAnswer.split(',');\n\n// remove duplicates\nwords = question.functions.set(list);\n\n// tell the student if they repeated a word\n// could give 0 credit and abandon marking at this point\nif(words.length3,1,random(1,2))", "templateType": "anything", "group": "Ungrouped variables", "name": "distance", "description": "

Desired distance of codewords from the base word

"}, "field_size": {"definition": "3", "templateType": "anything", "group": "Ungrouped variables", "name": "field_size", "description": "

Number of digits in the code.

"}, "ball": {"definition": "hamming_ball(base_word,distance,field_size)", "templateType": "anything", "group": "Ungrouped variables", "name": "ball", "description": "

List of the codewords the given distance from the base word

"}, "ball_text": {"definition": "'$'+join(ball,'$, $')+'$'", "templateType": "anything", "group": "Ungrouped variables", "name": "ball_text", "description": "

A list of the codewords, wrapped in LaTeX.

\n

Done in this convoluted way because MathJax doesn't do linebreaking very well, and if there are lots of code words then the line will be too wide for the page.

\n

Instead, each codeword is its own bit of LaTeX, and they're separated by plaintext commas.

"}, "word_length": {"definition": "random(2..5)", "templateType": "anything", "group": "Ungrouped variables", "name": "word_length", "description": "

Length of codewords

"}, "base_word": {"definition": "random_word(field_size,word_length)", "templateType": "anything", "group": "Ungrouped variables", "name": "base_word", "description": "

The base word given to the student

"}, "number_of_words": {"definition": "comb(word_length,distance)*(field_size-1)^distance", "templateType": "anything", "group": "Ungrouped variables", "name": "number_of_words", "description": "

The number of codewords which are the desired distance away from the base word

"}}, "metadata": {"notes": "

Gives some interactive help in writing the list as easy make mistakes.

", "description": "

Given a codeword in $w=\\mathbb{Z}^4_3$ find and list all codewords at Hamming distance $1$ from $w$.

", "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/"}]}