突击测验:解决数学谜题? [英] Pop Quiz: Solve the math puzzle?
本文介绍了突击测验:解决数学谜题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了一个网上的文章大约三年级的数学在越南。我想这将是有趣的,看看我们如何能够解决这个问题。在数学或编程的方式。
我写了一个测试功能对于这一点,随意将它改编成任何一种编程语言,你是舒服:
VAR答案= [1,1,1,1,1,1,1,1,1,1];
VAR isCorrect =功能(回答){
返回((((((((((((一个[0] 13)*一[1])/一个[2])+一个[3])+ 12)*一个[4]) - 一〔 5]) - 11)+一个[6])*一个[7])/一个[8]) - 10)=== 66;
};
的规则是应该有数组中没有重复的号码。 接受的数字是1-9。
解决方案
从限制进口*
高清公式(A,B,C,D,E,F,G,H,I):
返回ABS(A +(13 *(B / C))+ D +(12 * E) - F -
11 +((G * H)/ I) - 10 - 66)< 0.001
如果__name__ =='__main__':
all_vals = [浮动(我)对我的xrange(1,10)
P =问题()
[p.addVariable(L,all_vals)为L'ABCDEFGHI']
p.addConstraint(AllDifferentConstraint())
p.addConstraint(FunctionConstraint(式),'ABCDEFGHI)
结果= p.getSolution()
打印[保安局局长在排序(result.items(),键=拉姆达(K,V):K)]
答案是:
[('A',9.0),('B',8.0),('C',6.0),
(D,2.0),('E',4.0),('F',1.0),
('G',5.0),('H',7.0),(i的,3.0)]
I found a article online about a 3rd grade math in Vietnam. I guess it would be interesting to see how we can solve this problem. In mathematical or programmatic way.
I wrote a test function for this, feel free to adapt it into any programming language you are comfortable with :
var answer = [1,1,1,1,1,1,1,1,1,1];
var isCorrect = function (answer) {
return ((((((((((((a[0]+13)*a[1])/a[2])+a[3])+12)*a[4])-a[5])-11)+a[6])*a[7])/a[8])-10) === 66;
};
The rule is there should be no repeatable number in the array. Numbers accepted are 1-9.
解决方案
from constraint import *
def formula(a, b, c, d, e, f, g, h, i):
return abs(a + (13 * (b / c)) + d + (12 * e) - f -
11 + ((g * h) / i) - 10 - 66) < 0.001
if __name__ == '__main__':
all_vals = [float(i) for i in xrange(1, 10)]
p = Problem()
[p.addVariable(l, all_vals) for l in 'abcdefghi']
p.addConstraint(AllDifferentConstraint())
p.addConstraint(FunctionConstraint(formula), 'abcdefghi')
result = p.getSolution()
print [s for s in sorted(result.items(), key=lambda (k,v): k)]
The answers are:
[('a', 9.0), ('b', 8.0), ('c', 6.0),
('d', 2.0), ('e', 4.0), ('f', 1.0),
('g', 5.0), ('h', 7.0), ('i', 3.0)]
这篇关于突击测验:解决数学谜题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文