// Numbas version: exam_results_page_options {"name": "Lois's copy of 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": [{"ungrouped_variables": ["pi1", "pi2"], "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": ""}, "advice": "

\n

Possible solutions are shown below -- but remember that these are not unique.

\n

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

\n

\n

b)  Recall that you can just write each cycle in turn as a product of transpositions. \\[ \\var{as_transpositions(pi2)} \\]

", "preamble": {"css": "", "js": ""}, "extensions": ["permutations"], "statement": "

For this question you need to enter a transposition using commas between the terms in it. Do not leave spaces between each transposition in a product (composition).

", "tags": [], "rulesets": {}, "parts": [{"showCorrectAnswer": true, "marks": 0, "type": "gapfill", "gaps": [{"showCorrectAnswer": true, "marks": 1, "displayAnswer": "{as_transpositions(pi1)}", "type": "patternmatch", "answer": "", "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "variableReplacements": [], "matchMode": "regex", "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}"}}}], "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "variableReplacements": [], "scripts": {}, "prompt": "

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

\n

$\\pi_1 = $ [[0]]

"}, {"showCorrectAnswer": true, "marks": 0, "type": "gapfill", "gaps": [{"showCorrectAnswer": true, "marks": 1, "displayAnswer": "{as_transpositions(pi2)}", "type": "patternmatch", "answer": "", "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "variableReplacements": [], "matchMode": "regex", "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}"}}}], "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "variableReplacements": [], "scripts": {}, "prompt": "

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

\n

$\\pi_2 = $ [[0]]

"}], "functions": {"sum": {"language": "javascript", "type": "number", "parameters": [["l", "list"]], "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 += '^{'+factors[i]+'}';\n }\n }\n}\nreturn out;"}, "tracemap": {"language": "javascript", "type": "string", "parameters": [["n", "number"], ["perms", "list"]], "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;"}, "randomcycle": {"language": "javascript", "type": "list", "parameters": [["n", "number"]], "definition": "var off = Numbas.math.randomint(n);\nvar d = Numbas.math.deal(n);\nwhile(d[off]==off) {\n d = Numbas.math.deal(n);\n}\nvar out = [];\nfor(var i = 0;i0) {\n out += ' + ';\n }\n out += l[i]\n t += l[i];\n}\nout += ' = '+t;\nreturn out;"}, "primepowerfactors": {"language": "javascript", "type": "list", "parameters": [["n", "number"]], "definition": "var factors = Numbas.math.factorise(n);\nvar out = [];\nfor(var i=0;i1) {\n out += ' and ';\n } else if(i>0) {\n out += ', ';\n }\n out += '$'+l[i]+'$';\n}\nreturn out;"}, "permfrompartition": {"language": "javascript", "type": "list", "parameters": [["cycle_sizes", "list"]], "definition": "var to = [];\nvar offset = 0;\nfor(var i=0; i