(s)
Find solutions to alphametic equations.

    >>> solve('SEND + MORE == MONEY')
    9567 + 1085 == 10652
Find solutions to alphametic equations.
Find solutions to alphametic equations .
def alphametics(s):
    """Find solutions to alphametic equations.

    >>> solve('SEND + MORE == MONEY')
    9567 + 1085 == 10652
    """
    words = re.findall("[A-Za-z]+", s)
    chars = set("".join(words))         # Characters to be substituted.
    assert len(chars) <= 10             # There are only ten possible digits.
    firsts = set(w[0] for w in words)   # First letters of each of word.
    chars = "".join(firsts) + "".join(chars - firsts)
    n = len(firsts)                     # chars[:n] cannot be assigned zero.
    for perm in permutations("0123456789", len(chars)):
        if "0" not in perm[:n]:
            trans = str.maketrans(chars, "".join(perm))
            equation = s.translate(trans)
            if eval(equation):
                yield equation
def alphametics ( s ) : words = re . findall ( "[A-Za-z]+" , s ) chars = set ( "" . join ( words ) ) # Characters to be substituted. assert len ( chars ) <= 10 # There are only ten possible digits. firsts = set ( w [ 0 ] for w in words ) # First letters of each of word. chars = "" . join ( firsts ) + "" . join ( chars - firsts ) n = len ( firsts ) # chars[:n] cannot be assigned zero. for perm in permutations ( "0123456789" , len ( chars ) ) : if "0" not in perm [ : n ] : trans = str . maketrans ( chars , "" . join ( perm ) ) equation = s . translate ( trans ) if eval ( equation ) : yield equation