// Numbas version: exam_results_page_options {"name": "Euclidean Algorithm", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Euclidean Algorithm", "tags": [], "metadata": {"description": "

This question aims at getting the students to demonstrate their ability to apply the Euclidean algorithm to find the GCD between two numbers.

\n

We provide two randomly generated numbers and ask the students to enter the steps of the Euclidean algorithm, as well as the GCD between the numbers.

", "licence": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International"}, "statement": "

Euclidean Algorithm

\n

Apply the Euclidean algorithm to find the greatest common denominator between {pq[0]} and {pq[1]}. Show the steps.

", "advice": "

In order to apply the Euclidean algorithm to find the gcd, you need to apply integer division repeatedly, until the remainder is 0.

\n

Once you know the gcd between two numbers $p$ and $q$ you can find their lcm using the following formula: \\[\\mathrm{lcm}(p,q) = \\frac{p\\times q}{\\mathrm{gcd}(p,q)} \\]

", "rulesets": {}, "extensions": [], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"g": {"name": "g", "group": "Solutions", "definition": "Matrix(euclid)", "description": "

The steps from Euclid, stored in a matrix (for the purpose of checking the solution).

", "templateType": "anything", "can_override": false}, "m1": {"name": "m1", "group": "Random parameters", "definition": "repeat(random(2..9),random(2..4))", "description": "", "templateType": "anything", "can_override": false}, "pq": {"name": "pq", "group": "Random parameters", "definition": "common_multiples(r0,m1)", "description": "", "templateType": "anything", "can_override": false}, "r0": {"name": "r0", "group": "Random parameters", "definition": "random(2 .. 30#1)", "description": "

Number of elements in the array.

", "templateType": "randrange", "can_override": false}, "l": {"name": "l", "group": "Solutions", "definition": "pq[0]*pq[1]/r0", "description": "

Lowest common multiple of the numbers in pq.

", "templateType": "anything", "can_override": false}, "euclid": {"name": "euclid", "group": "Solutions", "definition": "euclidean(pq[0],pq[1])", "description": "

This variable contains the steps of Euclid's algorithm. Each row contains four numbers that correspond to the integer division performed at that step.

", "templateType": "anything", "can_override": false}, "ee": {"name": "ee", "group": "Ungrouped variables", "definition": "euclid[1]", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "pq[0]<5000 && pq[0]>200 && pq[1]<5000 && pq[1]>100 && numrows(g)>2", "maxRuns": "100"}, "ungrouped_variables": ["ee"], "variable_groups": [{"name": "Random parameters", "variables": ["r0", "m1", "pq"]}, {"name": "Solutions", "variables": ["euclid", "g", "l"]}], "functions": {"common_multiples": {"parameters": [["r0", "number"], ["factors", "list"]], "type": "list", "language": "javascript", "definition": "// Generate a pair of numbers with n as a common divisor.\n//var n = factors.length;\nvar r1 = r0;\nvar r2 = 0;\nvar l = [r1];\n//for(var i=0;i0) {\n m = Math.floor(r0/r1);\n r2 = r0%r1;\n l.push([r0,m,r1,r2]);\n r0 = r1;\n r1 = r2;\n}\nreturn l;"}}, "preamble": {"js": "", "css": ".matrix-input .matrix .cell:nth-child(2)::after {\n content: ' = ';\n}\n.matrix-input .matrix .cell:nth-child(4)::before {\n content: '\u00d7 ';\n}\n.matrix-input .matrix .cell:last-child::before {\n content: ' + ';\n}\n\n.matrix-input .matrix .cell:nth-child(12) {\n margin-right: 0;\n padding-right: 0;\n}\n\n.matrix-input .matrix .cell:nth-child(4) {\n margin-left: 0;\n padding-left: 0;\n}\n\n.matrix-input .left-bracket, .matrix-input .right-bracket {\n display: none !important;\n}\n\nlabel.num-columns { display: none;}\n/*label.num-rows:before {content: 'Number of Steps:';visibility: visible}\nlabel.num-rows {visibility: hidden;}\nlabel.num-rows input {visibility:visible;}*/\n\n.penaltyMessage {font-weight: bold; color: red}"}, "parts": [{"type": "matrix", "useCustomName": true, "customName": "Part a) Algorithm", "marks": 1, "scripts": {"mark": {"script": "var variables = this.question.scope.variables;\nvar unwrap = Numbas.jme.unwrapValue;\n\nvar g = unwrap(variables.g);\nvar A = this.studentAnswer;\n\nvar nrows = A.length;\nvar ncols = A[0].length;\n\nconsole.log(\"Hello\")\n\nif(ncols != 4) {this.setCredit(0,\"You need to have 4 entries on each line.\");return;}\nif(nrows != g.length) {this.setCredit(0,\"Wrong number of steps.\");return;}\n\nfor(i=0;iPlease enter all the steps of the Euclidean algorithm below (please enter the number of steps you need in the \"Rows:\" box.)

", "correctAnswer": "g", "correctAnswerFractions": false, "numRows": 1, "numColumns": "4", "allowResize": true, "tolerance": 0, "markPerCell": false, "allowFractions": false, "minColumns": "4", "maxColumns": "4", "minRows": 1, "maxRows": 0}, {"type": "numberentry", "useCustomName": true, "customName": "Part b) gcd", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

gcd({pq[0]},{pq[1]})=

", "minValue": "r0", "maxValue": "r0", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "Part c) LCM", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Lowest Common Multiple

\n

Use the information above to calculate the lowest common multiple between {pq[0]} and {pq[1]}.

\n

lcm({pq[0]},{pq[1]})=

", "minValue": "l", "maxValue": "l", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Julien Ugon", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3575/"}]}]}], "contributors": [{"name": "Julien Ugon", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3575/"}]}