randRange(2, 3)
_.map(_.range(N), function() {
return randFromArray(["decimal", "percentage", "fraction", "fraction"]);
}).slice(0, N)
_.map(TYPES, function(x) {
return randFromArray([2, 4, 5, 8, 10, 20, 25, 40, 50, 100]);
})
_.map(DENOMINATORS, function(d) {
return randRangeNonZero(-d * 2, d * 2);
})
_.map(DENOMINATORS, function(d, i) {
return roundTo(3, NUMERATORS[i] / d);
})
_.map(TYPES, function(t, i) {
if (t === "fraction") {
return fraction(NUMERATORS[i], DENOMINATORS[i]);
} else if (t === "percentage") {
return roundTo(3, 100 * DECIMALS[i]) + "\\%";
} else {
return DECIMALS[i];
}
})
(function() {
var arr = [];
for (var i = 0; i < N; i++) {
if (TYPES[i] !== 'decimal') {
arr.push(i);
}
}
return arr;
})()
(function() {
var x = 0;
for (var i = 0; i < N; i++) {
x += NUMERATORS[i] / DENOMINATORS[i];
}
return roundTo(3, x);
})()
NUMS[0] + NUMS[1] + NUMS[2] = {?}
SOLUTION
First get all of the numbers in decimal form.
\qquadNUMS[i] = DECIMALS[i]
\qquad
NUMS[i] = fraction(roundTo(3, NUMERATORS[i] * 100 / DENOMINATORS[i]), 100) = DECIMALS[i]
Now we have:
\qquad
DECIMALS[0] + DECIMALS[1] + DECIMALS[2] = {?}
\qquad
DECIMALS[0] + DECIMALS[1] + DECIMALS[2] = SOLUTION