// Numbas version: exam_results_page_options {"name": "Find all words within given Hamming distance", "extensions": ["codewords", "permutations"], "custom_part_types": [], "resources": [], "navigation": {"showfrontpage": false, "preventleave": false, "allowregen": true}, "question_groups": [{"questions": [{"contributors": [{"profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/3/", "name": "Christian Lawson-Perfect"}, {"profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/73/", "name": "Chris Graham"}, {"profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/", "name": "Christian Lawson-Perfect"}], "rulesets": {}, "type": "question", "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}$.

", "ungrouped_variables": ["word_length", "field_size", "base_word", "radius", "sphere", "sphere_string"], "functions": {}, "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

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

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}$.

", "variablesTest": {"condition": "len(sphere)<15 and len(sphere)>3", "maxRuns": 100}, "variable_groups": [], "tags": [], "parts": [{"variableReplacements": [], "scripts": {"mark": {"order": "instead", "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;iEnter your answer as a list of codewords, separated by commas. For example: 0000, 0001, 0002.

", "variableReplacementStrategy": "originalfirst", "marks": "2", "customMarkingAlgorithm": ""}], "preamble": {"css": "", "js": ""}, "extensions": ["codewords", "permutations"], "variables": {"sphere_string": {"templateType": "anything", "name": "sphere_string", "group": "Ungrouped variables", "description": "

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

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

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

Number of choices of digit

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

Length of words

", "definition": "random(3..6)"}, "base_word": {"templateType": "anything", "name": "base_word", "group": "Ungrouped variables", "description": "

The centre of the ball.

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

All words whose Hamming distance from base_word is radius.

", "definition": "hamming_sphere(base_word,radius)"}}, "name": "Find all words within given Hamming distance"}], "pickingStrategy": "all-ordered"}], "contributors": [{"profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/3/", "name": "Christian Lawson-Perfect"}, {"profile_url": "https://numbas-editor.mas.ncl.ac.uk/accounts/profile/73/", "name": "Chris Graham"}, {"profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/", "name": "Christian Lawson-Perfect"}]}