如何评价简单代数运算的难度
How to rate to difficulty of simple algebra operations
我正在编写一个简单的应用程序来帮助我女儿练习基础代数(一年级)。我想根据操作的难度为每个响应分配一个分数,例如,2+2 的价值小于 12-7。
你知道我可以查找并适应我的需求的任何现有算法吗?
编辑
- 如果您想查看该应用程序 https://algebro.herokuapp.com
- 如果你想看代码https://gitlab.com/etozzato/algebro
**编辑←**
试图使问题更具体 ;)
给定两个整数和一个基本的代数运算
算法输入:int a,b
和string operation
算法输出:float difficulty
→ 哪些因素可以帮助推断一个困难的系数?
- 我肯定会看看输入的数字,它们的距离可以是
在确定操作的复杂性方面具有重要意义。 10 + 1 明显比 7 + 5 容易,因为(当不记和立即反应时)它需要更长的计算时间;
- 作为对先前声明的修正,common/simple 参数应降低操作的复杂性:0 或 10 是一个很好的例子;
我不知道有什么算法可以找到方程的 "difficulty",但如果我有更多时间,我可能会尝试使用 this 之类的东西......即使仅供阅读,概念可能适用于算术。
无论如何,这里有一个超级愚蠢的 post-midnight crack,可以通过一些调整来实现极其 basic 的算法。您可以调整 factors/weights 但这可能会让您入门。祝你好运!
function get_difficulty (eq) {
var difficulty = 0;
var settings = {
terms_factor : 3, //Multiply by the number of terms in an equation
digits_factor : 2, //Multiply by the number of digits in each term
negative_weight : 2, //Add this if subtracting two numbers in the equation yields a negative number
operations : {
"+" : 1,
"-" : 2,
"*" : 4,
"/" : 6,
"=" : 0
}
};
eq += "=";
var ptr = 0;
var terms = 0;
var prev_term = null;
var len = eq.length;
var stack = [ ];
var is_numeric = function (n) {
return /\d+/.test (n); //Not a brilliant way but works for basic arithmetic
};
while (ptr < len) {
var tok = eq [ptr];
if (tok !== " " && tok !== "(" && tok !== ")") {
if (is_numeric (tok)) {
stack.push (tok);
} else if (tok in settings.operations) {
var curr_term = parseInt (stack.join (""));
if (prev_term !== null && curr_term > prev_term && ["-", "="].indexOf (tok) !== -1) {
difficulty += settings.negative_weight;
}
difficulty += stack.length * settings.digits_factor;
prev_term = curr_term;
stack = [ ];
terms++;
difficulty += settings.operations [tok];
} else {
console.log ("Unknown token: " + tok);
}
}
ptr++;
}
difficulty += terms * settings.terms_factor;
return difficulty;
}
console.log (get_difficulty (" 2 + 2 ")); //11
console.log (get_difficulty (" 12 - 7 ")); //14
console.log (get_difficulty (" 7 - 12 ")); //16
console.log (get_difficulty (" 5 - 5 ")); //12
console.log (get_difficulty (" 5 - 1205 ")); //20
console.log (get_difficulty (" 5 - 1205 * 35 ")); //29
console.log (get_difficulty (" 5 * 40 ")); //18
console.log (get_difficulty (" 102 - 5 / 13 + 32 ")); //39
console.log (get_difficulty (" 100 - 100 ")); //20
console.log (get_difficulty (" 32 - 12 ")); //16
console.log (get_difficulty (" 12 - 32 ")); //18
我正在编写一个简单的应用程序来帮助我女儿练习基础代数(一年级)。我想根据操作的难度为每个响应分配一个分数,例如,2+2 的价值小于 12-7。 你知道我可以查找并适应我的需求的任何现有算法吗?
编辑
- 如果您想查看该应用程序 https://algebro.herokuapp.com
- 如果你想看代码https://gitlab.com/etozzato/algebro
**编辑←**
试图使问题更具体 ;)
给定两个整数和一个基本的代数运算
算法输入:int a,b
和string operation
算法输出:float difficulty
→ 哪些因素可以帮助推断一个困难的系数?
- 我肯定会看看输入的数字,它们的距离可以是 在确定操作的复杂性方面具有重要意义。 10 + 1 明显比 7 + 5 容易,因为(当不记和立即反应时)它需要更长的计算时间;
- 作为对先前声明的修正,common/simple 参数应降低操作的复杂性:0 或 10 是一个很好的例子;
我不知道有什么算法可以找到方程的 "difficulty",但如果我有更多时间,我可能会尝试使用 this 之类的东西......即使仅供阅读,概念可能适用于算术。
无论如何,这里有一个超级愚蠢的 post-midnight crack,可以通过一些调整来实现极其 basic 的算法。您可以调整 factors/weights 但这可能会让您入门。祝你好运!
function get_difficulty (eq) {
var difficulty = 0;
var settings = {
terms_factor : 3, //Multiply by the number of terms in an equation
digits_factor : 2, //Multiply by the number of digits in each term
negative_weight : 2, //Add this if subtracting two numbers in the equation yields a negative number
operations : {
"+" : 1,
"-" : 2,
"*" : 4,
"/" : 6,
"=" : 0
}
};
eq += "=";
var ptr = 0;
var terms = 0;
var prev_term = null;
var len = eq.length;
var stack = [ ];
var is_numeric = function (n) {
return /\d+/.test (n); //Not a brilliant way but works for basic arithmetic
};
while (ptr < len) {
var tok = eq [ptr];
if (tok !== " " && tok !== "(" && tok !== ")") {
if (is_numeric (tok)) {
stack.push (tok);
} else if (tok in settings.operations) {
var curr_term = parseInt (stack.join (""));
if (prev_term !== null && curr_term > prev_term && ["-", "="].indexOf (tok) !== -1) {
difficulty += settings.negative_weight;
}
difficulty += stack.length * settings.digits_factor;
prev_term = curr_term;
stack = [ ];
terms++;
difficulty += settings.operations [tok];
} else {
console.log ("Unknown token: " + tok);
}
}
ptr++;
}
difficulty += terms * settings.terms_factor;
return difficulty;
}
console.log (get_difficulty (" 2 + 2 ")); //11
console.log (get_difficulty (" 12 - 7 ")); //14
console.log (get_difficulty (" 7 - 12 ")); //16
console.log (get_difficulty (" 5 - 5 ")); //12
console.log (get_difficulty (" 5 - 1205 ")); //20
console.log (get_difficulty (" 5 - 1205 * 35 ")); //29
console.log (get_difficulty (" 5 * 40 ")); //18
console.log (get_difficulty (" 102 - 5 / 13 + 32 ")); //39
console.log (get_difficulty (" 100 - 100 ")); //20
console.log (get_difficulty (" 32 - 12 ")); //16
console.log (get_difficulty (" 12 - 32 ")); //18