I want to track a series of scored questions in a single number (the total score
ID: 645839 • Letter: I
Question
I want to track a series of scored questions in a single number (the total score). Is that possible? and how?
For example, I have 30 questions with either 3 or 2 choices. For any given question, the user makes a selection and the score is incremented/decremented. Simple addition and subtraction is enough for that, but I want to also be able to go back and determine what they answered for any question.
My first thought is that this is some checksum operation or using some modula/shift operations (masking). So there could be a number of inputs such as the choice, question number, user number, etc.
Explanation / Answer
An int represents a fixed number of bits (usually 32 or 64). This is a measure of information content; it is fundamentally impossible to store more than this number of yes/no decisions in it. With three-way decisions the arithmetic becomes slightly more involved because they represent fractional numbers of bits (two three-way questions contain slightly more information than three two-way questions), but the principle remains.
Therefore using scalar values this way is a bad idea. It's fragile (as soon as your questionnaire grows above the magic number of steps, it breaks), and even while it works, it's expensive to encode and decode the information you actually want from the value it's stored in. The question therefore becomes: Why do you want to use an int? Are you sure structured data of some kind aren't an easier and better choice?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.