// Numbas version: finer_feedback_settings {"name": "Write a permutation as a product of transpositions", "extensions": ["permutations"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {"orderpossible": {"definition": "var factors = Numbas.math.factorise(n);\nvar t = 0;\nfor(var i=0;i1) {\n out += '^{'+factors[i]+'}';\n }\n }\n}\nreturn out;", "type": "string", "language": "javascript", "parameters": [["n", "number"]]}, "sum": {"definition": "var t = 0;\nfor(var i=0;i0) {\n var cycle_length = Math.pow(Numbas.math.primes[i],factors[i]);\n for(var j=0;j1) {\n out += ' and ';\n } else if(i>0) {\n out += ', ';\n }\n out += '$'+l[i]+'$';\n}\nreturn out;", "type": "string", "language": "javascript", "parameters": [["l", "list"]]}, "permfrompartition": {"definition": "var to = [];\nvar offset = 0;\nfor(var i=0; i0) {\n out += ' + ';\n }\n out += l[i]\n t += l[i];\n}\nout += ' = '+t;\nreturn out;", "type": "string", "language": "javascript", "parameters": [["l", "list"]]}, "randompartition": {"definition": "var l = [];\nwhile(n) {\n var t = Numbas.math.randomint(n)+1;\n l.push(t);\n n -= t;\n}\nreturn l;", "type": "list", "language": "javascript", "parameters": [["n", "number"]]}, "tracemap": {"definition": "n -= 1;\nvar l = perms.length;\nvar out = ''+(n+1);\nfor(var i=l-1;i>=0;i--) {\n n = perms[i].map(n);\n out += ' \\\\to '+(n+1);\n}\nreturn out;", "type": "string", "language": "javascript", "parameters": [["n", "number"], ["perms", "list"]]}}, "name": "Write a permutation as a product of transpositions", "tags": ["permutations"], "type": "question", "advice": "

a)

\n

\\[ \\var{as_transpositions(pi1)} \\]

\n

b)

\n

\\[ \\var{as_transpositions(pi2)} \\]

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

Write the permutation $\\pi_1 = \\var{pi1}$ as a product of transpositions.

\n

$\\pi_1 = $ [[0]]\n

", "marks": 0, "gaps": [{"marks": 1, "showCorrectAnswer": true, "displayAnswer": "{as_transpositions(pi1)}", "scripts": {"validate": {"order": "instead", "script": "var Permutation = Numbas.extensions.permutations.Permutation;\ntry {\n Permutation.parse(this.studentAnswer);\n} catch(e) {\n this.giveWarning(\"Invalid notation\");\n return false;\n}\nreturn true;"}, "mark": {"order": "instead", "script": "this.setCredit(0);\nvar Permutation = Numbas.extensions.permutations.Permutation;\ntry {\n var p = Permutation.fromString(this.studentAnswer);\n} catch(e) {\n this.setCredit(0,\"Invalid notation\");\n return;\n}\nif(!Permutation.is_transpositions(this.studentAnswer)) {\n this.setCredit(0,\"Your answer is not a product of transpositions\");\n return;\n}\nvar unwrapValue = Numbas.jme.unwrapValue;\nvar p_totranspose = unwrapValue(question.scope.variables.pi1);\nif(p.equal(p_totranspose)) {\n this.setCredit(1,\"Correct!\");\n} else {\n this.setCredit(0,\"Wrong\");\n}"}}, "answer": "", "type": "patternmatch"}], "showCorrectAnswer": true, "scripts": {}, "type": "gapfill"}, {"prompt": "

Write the permutation $\\pi_2 = \\var{pi2}$ as a product of transpositions.

\n

$\\pi_2 = $ [[0]]\n

", "marks": 0, "gaps": [{"marks": 1, "showCorrectAnswer": true, "displayAnswer": "{as_transpositions(pi2)}", "scripts": {"validate": {"order": "instead", "script": "var Permutation = Numbas.extensions.permutations.Permutation;\ntry {\n Permutation.parse(this.studentAnswer);\n} catch(e) {\n this.giveWarning(\"Invalid notation\");\n return false;\n}\nreturn true;"}, "mark": {"order": "instead", "script": "this.setCredit(0);\nvar Permutation = Numbas.extensions.permutations.Permutation;\ntry {\n var p = Permutation.fromString(this.studentAnswer);\n} catch(e) {\n this.setCredit(0,\"Invalid notation\");\n return;\n}\nif(!Permutation.is_transpositions(this.studentAnswer)) {\n this.setCredit(0,\"Your answer is not a product of transpositions\");\n return;\n}\nvar unwrapValue = Numbas.jme.unwrapValue;\nvar p_totranspose = unwrapValue(question.scope.variables.pi2);\nif(p.equal(p_totranspose)) {\n this.setCredit(1,\"Correct!\");\n} else {\n this.setCredit(0,\"Wrong\");\n}"}}, "answer": "", "type": "patternmatch"}], "showCorrectAnswer": true, "scripts": {}, "type": "gapfill"}], "statement": "", "variable_groups": [], "progress": "in-progress", "preamble": {"css": "", "js": ""}, "variables": {"pi1": {"definition": "perm(randomcycle(random(5..9)))", "templateType": "anything", "group": "Ungrouped variables", "name": "pi1", "description": ""}, "pi2": {"definition": "perm(deal(random(11..17)))", "templateType": "anything", "group": "Ungrouped variables", "name": "pi2", "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/"}]}