As told to Julie Zelenski
A former CS107 TA was hired to work on a well-known online educational platform (name withheld to protect the guilty). He was Stanford-trained and well-prepared to corral those wily floats but the developers who had preceded him were somewhat less float-aware. Their failure to account for exceptional values created an embarrassing vulnerability in the quiz feature.
Quiz items with a numeric response were optionally scored using a "tolerance" feature that accepted all responses within tolerance of the true answer as correct. For example, if the true answer was 200.7 and the tolerance was 0.01, responses within 1% of 200.7 would be scored as correct.
The code to score the student's quiz response looked something like this:
bool is_correct(const char *response, float target)
{
/* Is student response within acceptable tolerance of target?
- response : student's answer (string)
- target : instructor result (number)
*/
const float TOLERANCE = 0.01;
float val = strtof(response, NULL);
float at_most = TOLERANCE * fmax(fabs(val), fabs(target));
return fabs(val - target) <= at_most;
}
It wasn't long before enterprising students discovered a response that enabled them to ace every test. What is the magic answer?