// Numbas version: exam_results_page_options {"name": "Find all words within given Hamming distance", "extensions": ["codewords", "permutations"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"parts": [{"answer": "", "displayAnswer": "{sphere_string}", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "prompt": "

Enter your answer as a list of codewords, separated by commas. For example: 0000, 0001, 0002.

", "unitTests": [], "matchMode": "regex", "showFeedbackIcon": true, "scripts": {"mark": {"script": "// check student's answer is a comma-separated list of codewords\nthis.valid = /^\\s*\\d+(\\s*,\\s*\\d+)*\\s*$/.test(this.studentAnswer);\nif(!this.valid) {\n this.setCredit(0,\"Your answer is not a comma-separated list of codewords\");\n}\n\n// split up into individual codewords\nvar strings = this.studentAnswer.trim().split(/\\s*,\\s*/g);\n\n// parse each string as a codeword object\nvar Codeword = Numbas.extensions.codewords.Codeword;\nvar TCodeword = Numbas.jme.types.TCodeword;\nvar words = strings.map(function(s) {\n var field_size = variables.field_size;\n for(var i=0;iLength of words

"}, "sphere": {"templateType": "anything", "group": "Ungrouped variables", "definition": "hamming_sphere(base_word,radius)", "name": "sphere", "description": "

All words whose Hamming distance from base_word is radius.

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

Number of choices of digit

"}, "sphere_string": {"templateType": "anything", "group": "Ungrouped variables", "definition": "join(map(string(x),x,sphere),', ')", "name": "sphere_string", "description": "

The list of words in sphere, as a string to be used as the displayed answer to the question.

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

The centre of the ball.

"}, "radius": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(1..word_length-1)", "name": "radius", "description": "

Radius of the Hamming sphere

"}}, "ungrouped_variables": ["word_length", "field_size", "base_word", "radius", "sphere", "sphere_string"], "name": "Find all words within given Hamming distance", "variable_groups": [], "preamble": {"css": "", "js": ""}, "variablesTest": {"condition": "len(sphere)<15 and len(sphere)>3", "maxRuns": 100}, "statement": "

Find all words $w \\in \\mathbb{Z}_{\\var{field_size}}^{\\var{word_length}}$ for which $d_\\mathrm{H}(w,\\var{base_word}) = \\var{radius}$.

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

Find all words with given Hamming distance from a given codeword.

"}, "functions": {}, "advice": "

Each word $w$ must differ from the word $\\var{base_word}$ in $\\var{radius}$ {pluralise(radius,\"place\",\"places\")}.

\n

There are $\\simplify{comb({word_length},{radius}) = {comb(word_length,radius)}}$ ways of choosing $\\var{radius}$ {pluralise(radius,\"digit\",\"digits\")} to change, and $\\var{field_size}-1 = \\var{field_size-1}$ {pluralise(field_size-1,\"choice\",\"choices\")} for each changed digit.

\n

That means that there are $\\simplify[]{{comb(word_length,radius)}*{field_size-1}^{radius}} = \\var{comb(word_length,radius)*(field_size-1)^radius}$ words $w$ with $d_\\mathrm{H}(w,\\var{base_word}) = \\var{radius}$.

", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/3/"}, {"name": "Chris Graham", "profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/73/"}, {"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": "Chris Graham", "profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/73/"}, {"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}