WWWDOT - GOOGLE = DOTCOM
C,D,E,G,L,M,O,T,W分别代表代表0-9之间的数字,彼此不能相等,W!=0, E、M可以互换请问,满足WWWDOT - GOOGLE = DOTCOM的有多少种情况? 再限定首位的G≠0,D≠0,可得3个解:
555378-177104=378274(E=M)
777589-188103=589486
777589-188106=589483 允许首位的G,d取0也无增解 2# hujunhua
555378-177104=378274(E=M) 这个应该不算的,不同字母不能相等 2# hujunhua
是用C/C++穷举,还是Mathematica,或者是分析出来的? Mathematica 9
Module[{c, d, e, g, l, m, o, t, w, A = 10^Range},
Do[{c, d, e, g, l, m, o, t, w} = x;
If[{w, w, w, d, o, t}.A - {g, o, o, g, l, e}.A == {d, o, t, c, o,
m}.A, Print@x], {x, Permutations, {9}]}]]
Permutations有了第二个参数时无法Compile 本帖最后由 chyanog 于 2013-3-2 20:50 编辑
想到了一个能Compile的办法,不知道能否更快
http://my-sort.googlecode.com/files/2013-03-02_204542.jpgcf = Compile[{{arr, _Integer, 2}},
Module[{c, d, e, g, l, m, o, t, w, A, B, C, T = 10^Range},
Do[{c, d, e, g, l, m, o, t, w} = x;
A = {w, w, w, d, o, t};
B = {g, o, o, g, l, e};
C = {d, o, t, c, o, m};
If, {x, arr}]],
CompilationTarget -> "C", RuntimeOptions -> "Speed"];
cf, {9}]] // AbsoluteTiming 还是直接解方程来得快。
f = FromDigits;(*函数名缩写*)
v = {c, d, e, g, l, m, o, t, w};
x = {w, w, w, d, o, t};
y = {g, o, o, g, l, e};
z = {d, o, t, c, o, m};
solv = Solve == f + f && And @@ (0 <= # <= 9 & /@ v), v, Integers];
sele = Select] == 9 &];
f /@ {x, y, z} /. sele
{{777589, 188103, 589486}, {777589, 188106, 589483}} 9# hujunhua
很好。不过我尝试过这样解方程,这个速度就极慢了Solve - f == f && And @@ (0 <= # <= 9 & /@ v) &&
LogicalExpand, v, Integers] // Timing
页:
[1]
2