SEND MORE MONEY の Pythonでの議論
https://stackoverflow.com/questions/37450302/send-more-money-puzzle-in-python


俺のような初学者のWolfram言語の練習にいい。

Wolfram Language 14.0.0 Engine for Microsoft Windows (64-bit)
Copyright 1988-2023 Wolfram Research, Inc.

In[1]:= str="SEND + MORE = MONEY";

In[2]:= Union@StringSplit[StringDelete[str,{" ","+","="}],""];

In[3]:= pm=Permutations[Range[0,9],{8}];

In[4]:= f[x_] := (
{d,e,m,n,o,r,s,y}=x;
Total[{s,e,n,d}*{1000,100,10,1}]+Total[{m,o,r,e}*{1000,100,10,1}]==Total[{m,o,n,e,y}*{10000,1000,100,10,1}] && s!=0 && m!=0
)

In[5]:= {d,e,m,n,o,r,s,y}=Flatten@Select[pm,f];

In[6]:= {s,e,n,d," + ",m,o,r,e," = ",m,o,n,e,y}

Out[6]= {9, 5, 6, 7, + , 1, 0, 8, 5, = , 1, 0, 6, 5, 2}