// Numbas version: exam_results_page_options {"name": "Invent your own question: binary encoding", "extensions": [], "custom_part_types": [{"source": {"pk": 1, "author": {"name": "Christian Lawson-Perfect", "pk": 7}, "edit_page": "/part_type/1/edit"}, "name": "Yes/no", "short_name": "yes-no", "description": "

The student is shown two radio choices: \"Yes\" and \"No\". One of them is correct.

", "help_url": "", "input_widget": "radios", "input_options": {"correctAnswer": "if(eval(settings[\"correct_answer_expr\"]), 0, 1)", "hint": {"static": true, "value": ""}, "choices": {"static": true, "value": ["Yes", "No"]}}, "can_be_gap": true, "can_be_step": true, "marking_script": "mark:\nif(studentanswer=correct_answer,\n correct(),\n incorrect()\n)\n\ninterpreted_answer:\nstudentAnswer=0\n\ncorrect_answer:\nif(eval(settings[\"correct_answer_expr\"]),0,1)", "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": "if(studentanswer=correct_answer,\n correct(),\n incorrect()\n)"}, {"name": "interpreted_answer", "description": "A value representing the student's answer to this part.", "definition": "studentAnswer=0"}, {"name": "correct_answer", "description": "", "definition": "if(eval(settings[\"correct_answer_expr\"]),0,1)"}], "settings": [{"name": "correct_answer_expr", "label": "Is the answer \"Yes\"?", "help_url": "", "hint": "An expression which evaluates to true or false.", "input_type": "mathematical_expression", "default_value": "true", "subvars": false}], "public_availability": "always", "published": true, "extensions": []}], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Invent your own question: binary encoding", "tags": [], "metadata": {"description": "

Guides the student through the process of writing an integer in binary. They can pick any number they like, then choose from a selection of methods, or just do their own method and have the answer checked.

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "", "advice": "", "rulesets": {}, "extensions": [], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"n": {"name": "n", "group": "Ungrouped variables", "definition": "3435", "description": "", "templateType": "anything", "can_override": false}, "largest_power_of_2": {"name": "largest_power_of_2", "group": "Ungrouped variables", "definition": "2^floor(log(working_n,2))", "description": "

The largest power of 2 less than or equal to n.

", "templateType": "anything", "can_override": false}, "powers": {"name": "powers", "group": "Ungrouped variables", "definition": "[]", "description": "", "templateType": "anything", "can_override": false}, "subtracting_powers_description": {"name": "subtracting_powers_description", "group": "Ungrouped variables", "definition": "latex(if(powers=[],\n \"{n}\",\n join(map(\"2^{p}\",p,powers), \" + \")+if(working_n>0, \" + {working_n}\", \"\")\n))", "description": "

The description of the current state of the process of subtracting the largest possible power of 2.

", "templateType": "anything", "can_override": false}, "working_n": {"name": "working_n", "group": "Ungrouped variables", "definition": "n", "description": "

The value that the student is working with at the current step.

", "templateType": "anything", "can_override": false}, "binary_encoding": {"name": "binary_encoding", "group": "Ungrouped variables", "definition": "tobinary(int(n))", "description": "", "templateType": "anything", "can_override": false}, "is_odd": {"name": "is_odd", "group": "Ungrouped variables", "definition": "mod(working_n,2)=1", "description": "

Is the working value odd?

", "templateType": "anything", "can_override": false}, "dividing_description": {"name": "dividing_description", "group": "Ungrouped variables", "definition": "latex(foldl(if(odd, \"({s}-1)/2\", \"{s}/2\"), s, odd, string(n), odds))", "description": "", "templateType": "anything", "can_override": false}, "odds": {"name": "odds", "group": "Ungrouped variables", "definition": "[]", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["n", "working_n", "largest_power_of_2", "powers", "subtracting_powers_description", "binary_encoding", "is_odd", "odds", "dividing_description"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "numberentry", "useCustomName": true, "customName": "Pick a number", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": false, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [{"label": "Next step", "rawLabel": "Next step", "otherPart": 1, "variableReplacements": [{"variable": "n", "definition": "interpreted_answer"}], "availabilityCondition": "answered", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Pick a positive integer. Any positive integer.

", "minValue": "1", "maxValue": "infinity", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "precisionType": "dp", "precision": 0, "precisionPartialCredit": 0, "precisionMessage": "You must write a whole number.", "strictPrecision": true, "showPrecisionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "information", "useCustomName": true, "customName": "Choose your path", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [{"label": "Repeatedly subtract the largest possible power of 2", "rawLabel": "Repeatedly subtract the largest possible power of 2", "otherPart": 2, "variableReplacements": [], "availabilityCondition": "", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}, {"label": "Repeatedly divide by 2, subtracting 1 if odd", "rawLabel": "Repeatedly divide by 2, subtracting 1 if odd", "otherPart": 6, "variableReplacements": [], "availabilityCondition": "", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}, {"label": "I'll use my own method", "rawLabel": "I'll use my own method", "otherPart": 10, "variableReplacements": [], "availabilityCondition": "", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

You chose $n = \\var{n}$.

\n

Your task is to write $n$ in binary.

\n

How would you like to do that?

"}, {"type": "numberentry", "useCustomName": true, "customName": "What's the largest power of 2?", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [{"label": "Next step", "rawLabel": "Next step", "otherPart": 2, "variableReplacements": [{"variable": "working_n", "definition": "working_n - interpreted_answer"}, {"variable": "powers", "definition": "powers + [round(log(interpreted_answer,2))]"}], "availabilityCondition": "answered and credit=1 and largest_power_of_2 < working_n", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}, {"label": "Next step", "rawLabel": "Next step", "otherPart": 3, "variableReplacements": [{"variable": "working_n", "definition": "working_n - interpreted_answer"}, {"variable": "powers", "definition": "powers + [log(interpreted_answer,2)]"}], "availabilityCondition": "answered and credit=1 and largest_power_of_2 = working_n", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

$\\var{n} = \\var{subtracting_powers_description}$

\n

What's the largest power of 2 less than or equal to $\\var{working_n}$?

", "minValue": "largest_power_of_2", "maxValue": "largest_power_of_2", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "information", "useCustomName": true, "customName": "Finished subtracting powers of 2", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [{"label": "Write the binary encoding", "rawLabel": "Write the binary encoding", "otherPart": 4, "variableReplacements": [], "availabilityCondition": "", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

$\\var{n} = \\var{subtracting_powers_description}$.

"}, {"type": "patternmatch", "useCustomName": true, "customName": "Write the binary encoding - subtracted powers", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [{"label": "I'd like a hint please", "rawLabel": "I'd like a hint please", "otherPart": 5, "variableReplacements": [], "availabilityCondition": "not (answered and credit=1)", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": "Write the binary encoding", "prompt": "

$\\var{n} = \\var{subtracting_powers_description}$.

\n

Now write the binary representation of $\\var{n}$.

\n

", "answer": "{binary_encoding}", "displayAnswer": "", "matchMode": "exact"}, {"type": "information", "useCustomName": true, "customName": "Binary encoding hint - subtracted powers", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": true, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

For each power of 2, from the largest one you wrote down to $2^0 = 1$, write a $1$ if that power is in your list, or a $0$ if it isn't.

"}, {"type": "yes-no", "useCustomName": true, "customName": "Subtract 1 if odd", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [{"label": "Subtract 1 and divide by 2", "rawLabel": "Subtract 1 and divide by 2", "otherPart": 6, "variableReplacements": [{"variable": "working_n", "definition": "(working_n-1)/2"}, {"variable": "odds", "definition": "odds+[1]"}], "availabilityCondition": "answered and credit=1 and is_odd and working_n > 1", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}, {"label": "Divide by 2", "rawLabel": "Divide by 2", "otherPart": 6, "variableReplacements": [{"variable": "working_n", "definition": "working_n/2"}, {"variable": "odds", "definition": "odds+[0]"}], "availabilityCondition": "answered and credit=1 and not is_odd and working_n > 1", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}, {"label": "Next step", "rawLabel": "Next step", "otherPart": 7, "variableReplacements": [{"variable": "working_n", "definition": "0"}, {"variable": "odds", "definition": "odds+[if(is_odd,1,0)]"}], "availabilityCondition": "answered and credit=1 and working_n in [0,1]", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

$\\var{working_n} = \\var{dividing_description}$

\n

Is $\\var{working_n}$ odd?

", "settings": {"correct_answer_expr": "is_odd"}}, {"type": "information", "useCustomName": true, "customName": "Finished dividing by 2", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [{"label": "Write the binary encoding", "rawLabel": "Write the binary encoding", "otherPart": 8, "variableReplacements": [], "availabilityCondition": "", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

$\\var{working_n} = \\var{dividing_description}$

"}, {"type": "patternmatch", "useCustomName": true, "customName": "Write the binary encoding - dividing by 2", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [{"label": "I'd like a hint, please", "rawLabel": "I'd like a hint, please", "otherPart": 9, "variableReplacements": [], "availabilityCondition": "not (answered and credit=1)", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": "Write the binary encoding", "prompt": "

$0 = \\var{dividing_description}$.

\n

Now write the binary representation of $\\var{n}$.

\n

", "answer": "{binary_encoding}", "displayAnswer": "", "matchMode": "exact"}, {"type": "information", "useCustomName": true, "customName": "Binary encoding hint - dividing by 2", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": true, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

$0 = \\var{dividing_description}$

\n

Adding a 0 to the end of the binary representation of $n$ gives you the binary representation of $2n$.

\n

You can use this to build up the binary representation of $\\var{n}$ while unravelling the expression above.

\n

So, starting with an empty string, read the expression from right to left, adding a $0$ when you see $/2$, or changing the rightmost $0$ to $1$ when you see $-1$.

"}, {"type": "patternmatch", "useCustomName": true, "customName": "Write the binary encoding - own method", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [{"label": "I'd like a hint, please", "rawLabel": "I'd like a hint, please", "otherPart": "", "variableReplacements": [], "availabilityCondition": "not (answered and credit=1)", "penalty": "", "penaltyAmount": 0, "lockAfterLeaving": false}], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": "Write the binary encoding", "prompt": "

Write the binary representation of $\\var{n}$.

", "answer": "{binary_encoding}", "displayAnswer": "", "matchMode": "exact"}], "partsMode": "explore", "maxMarks": 0, "objectives": [{"name": "Write the binary encoding", "limit": 1}], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "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/"}]}