fork download
  1. sendMoreMoney[s_]:=Module[{mkNumberList,mkSRules,wordToNumber,checker},
  2.  
  3. (* Functions *)
  4. mkNumberList[sx_]:=Module[{numberChecker,sn,nmax},
  5.  
  6. numberChecker[n_,l_]:=n//
  7. IntegerDigits[#,10]&//
  8. PadLeft[#,l]&//
  9. If[Length[DeleteDuplicates[#]]==l,
  10. #,
  11. {}]&;
  12.  
  13. sn=sx//
  14. Map[Characters,#]&//
  15. Flatten//
  16. DeleteDuplicates//
  17. Length;
  18.  
  19. nmax=Table[9,{i,sn}]//
  20. FromDigits;
  21.  
  22. ParallelTable[numberChecker[i,sn],{i,0,nmax}]//
  23. Select[#,#!={}&]&
  24. ];
  25.  
  26. mkSRules[sl_,nl_]:=Module[{nls},
  27.  
  28. nls=nl//
  29. Map[ToString,#]&;
  30.  
  31. MapThread[List,{sl,nls}]//
  32. Map[#[[1]]->#[[2]]&,#]&
  33. ];
  34.  
  35. wordToNumber[sx_,nl_]:=Module[{sl},
  36.  
  37. sl=sx//
  38. Map[Characters,#]&//
  39. Flatten//
  40. DeleteDuplicates;
  41.  
  42. sx//
  43. Map[Characters,#]&//
  44. Map[StringReplace[#,mkSRules[sl,nl]]&,#]&//
  45. Map[ToExpression,#]&//
  46. Map[FromDigits,#]&
  47. ];
  48.  
  49. checker[sx_,wnl_]:=Module[{tf1,tf2},
  50.  
  51. tf1=(wnl[[1]]+wnl[[2]]==wnl[[3]]);
  52.  
  53. tf2=Module[{sll,wnll},
  54.  
  55. sll=sx//Map[Characters,#]&//Map[Length,#]&;
  56.  
  57. wnll=wnl//Map[IntegerDigits[#,10]&,#]&//Map[Length,#]&;
  58.  
  59. sll==wnll];
  60.  
  61. If[And[tf1,tf2],
  62. wnl,
  63. {}]
  64. ];
  65.  
  66. (* Results *)
  67. s//
  68. mkNumberList//
  69. ParallelMap[wordToNumber[s,#]&,#]&//
  70. ParallelMap[checker[s,#]&,#]&//
  71. Select[#,#!={}&]&
  72. ];
Not running #stdin #stdout 0s 0KB
stdin
sendMoreMoney[{"SEND", "MORE", "MONEY"}]
stdout
Standard output is empty