// Numbas version: finer_feedback_settings {"name": "Write a permutation as a product of disjoint cycles", "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 disjoint cycles", "tags": ["permutations"], "type": "question", "advice": "

Each set of brackets represents a cycle, with each number being mapped to the one on its right, and the last number in the sequence mapped to the first.

\n

Follow each number through the cycles, starting with the rightmost cycle and reading leftwards. For example, here's how $1$ is mapped to $\\var{prod[1]}$:

\n

\\[ \\var{latex(tracemap(1,perms))} \\]

\n

Then repeat this for $\\var{prod[1]}$, until you get back to $1$. This is a single cycle. If any number is not included in this cycle, repeat this process starting at that number to get another, disjoint, cycle. Some numbers are mapped to themselves - these are trivial cycles and you don't need to write them down. Once you've covered every number, you should have the following:

\n

\\[ \\var{prod} \\]

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

Write as a product of disjoint cycles

\n

\\[\\var{perms[0]} \\var{perms[1]} \\var{perms[2]} \\var{perms[3]} \\]

", "marks": 1, "showCorrectAnswer": true, "displayAnswer": "{show(prod)}", "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": "var 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_disjoint(this.studentAnswer)) {\n this.setCredit(0,\"Your cycles are not disjoint\");\n return;\n}\nvar unwrapValue = Numbas.jme.unwrapValue;\nvar prod = unwrapValue(question.scope.variables.prod);\nif(p.equal(prod)) {\n this.setCredit(1,\"Correct!\");\n} else {\n this.setCredit(0,\"Wrong\");\n}"}}, "answer": "", "type": "patternmatch"}], "statement": "", "variable_groups": [], "progress": "in-progress", "preamble": {"css": "", "js": ""}, "variables": {"perms": {"definition": "repeat(perm(randomcycle(n)),4)", "templateType": "anything", "group": "Ungrouped variables", "name": "perms", "description": ""}, "prod": {"definition": "compose(perms[0],perms[1],perms[2],perms[3])", "templateType": "anything", "group": "Ungrouped variables", "name": "prod", "description": ""}, "n": {"definition": "random(4..9)", "templateType": "anything", "group": "Ungrouped variables", "name": "n", "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/"}]}