chyanog 发表于 2013-2-25 19:23:01

WWWDOT - GOOGLE = DOTCOM

C,D,E,G,L,M,O,T,W分别代表代表0-9之间的数字,彼此不能相等,W!=0, E、M可以互换
请问,满足WWWDOT - GOOGLE = DOTCOM的有多少种情况?

hujunhua 发表于 2013-2-26 08:51:25

再限定首位的G≠0,D≠0,可得3个解:
555378-177104=378274(E=M)
777589-188103=589486
777589-188106=589483

hujunhua 发表于 2013-2-26 09:02:37

允许首位的G,d取0也无增解

chyanog 发表于 2013-2-26 15:39:45

2# hujunhua
555378-177104=378274(E=M) 这个应该不算的,不同字母不能相等

chyanog 发表于 2013-2-27 17:25:56

2# hujunhua
是用C/C++穷举,还是Mathematica,或者是分析出来的?

hujunhua 发表于 2013-2-27 23:16:19

Mathematica 9

chyanog 发表于 2013-2-28 17:24:13


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:48:43

本帖最后由 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

hujunhua 发表于 2013-3-2 22:33:57

还是直接解方程来得快。
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}}

chyanog 发表于 2013-3-3 00:23:53

9# hujunhua
很好。不过我尝试过这样解方程,这个速度就极慢了Solve - f == f && And @@ (0 <= # <= 9 & /@ v) &&
   LogicalExpand, v, Integers] // Timing
页: [1] 2
查看完整版本: WWWDOT - GOOGLE = DOTCOM