{ "source": { "author": { "name": "Christian Lawson-Perfect" } }, "name": "Write a permutation in two-line form", "short_name": "write-a-permutation-in-two-line-form", "description": "

The student must write out a permutation (an element of $S_n$) in two-line form: the top line always contains the numbers 1 to $n$, and on the bottom line they must write the numbers that they are mapped to.

", "help_url": "", "input_widget": "matrix", "input_options": { "correctAnswer": "matrix(map(settings[\"correctAnswer\"][i],i,1..settings[\"size\"]))", "hint": { "static": true, "value": "" }, "allowResize": { "static": true, "value": false }, "numRows": { "static": true, "value": 1 }, "numColumns": { "static": false, "value": "settings[\"size\"]" }, "parseCells": { "static": true, "value": true }, "allowedNotationStyles": { "static": true, "value": [ "plain" ] }, "allowFractions": { "static": true, "value": false }, "showBrackets": { "static": true, "value": true }, "rowHeaders": { "static": false, "value": "[]" }, "columnHeaders": { "static": false, "value": "map(string(n),n,1..settings[\"size\"])" } }, "can_be_gap": true, "can_be_step": true, "marking_script": "mark:\napply(valid_permutation);\ncorrectif(student_permutation=settings[\"correctAnswer\"])\n\nstudent_numbers:\nlist(studentAnswer[0])\n\nstudent_permutation:\npermutation(map(x-1,x,student_numbers))\n\nvalid_permutation:\n assert(all(map(isint(x) and x>=1 and x<=settings[\"size\"], x, student_numbers)),\n fail(\"Your answer is not a valid permutation: each entry must be one of the numbers 1 \u2026 {settings['size']}.\")\n );\n assert(len(set(student_numbers))=settings[\"size\"],\n fail(\"Your answer is not a valid permutation: some entries occur more than once.\")\n )\n\ninterpreted_answer:\nstudent_permutation", "marking_notes": [ { "name": "mark", "description": "This is the main marking note. It should award credit and provide feedback based on the student's answer.", "definition": "apply(valid_permutation);\ncorrectif(student_permutation=settings[\"correctAnswer\"])" }, { "name": "student_numbers", "description": "

The numbers that the student typed.

", "definition": "list(studentAnswer[0])" }, { "name": "student_permutation", "description": "", "definition": "permutation(map(x-1,x,student_numbers))" }, { "name": "valid_permutation", "description": "", "definition": " assert(all(map(isint(x) and x>=1 and x<=settings[\"size\"], x, student_numbers)),\n fail(\"Your answer is not a valid permutation: each entry must be one of the numbers 1 \u2026 {settings['size']}.\")\n );\n assert(len(set(student_numbers))=settings[\"size\"],\n fail(\"Your answer is not a valid permutation: some entries occur more than once.\")\n )" }, { "name": "interpreted_answer", "description": "A value representing the student's answer to this part.", "definition": "student_permutation" } ], "settings": [ { "name": "correctAnswer", "label": "Correct answer", "help_url": "", "hint": "", "input_type": "code", "default_value": "", "evaluate": true }, { "name": "size", "label": "Size", "help_url": "", "hint": "", "input_type": "code", "default_value": "", "evaluate": true } ], "public_availability": "always", "published": true, "extensions": [] }