#!/usr/bin/python import sys elements = [ "Ac", "Ag", "Al", "Am", "Ar", "As", "At", "Au", "B", "Ba", "Be", "Bh", "Bi", "Bk", "Br", "C", "Ca", "Cd", "Ce", "Cf", "Cl", "Cm", "Co", "Cr", "Cs", "Cu", "Db", "Ds", "Dy", "Er", "Es", "Eu", "F", "Fe", "Fm", "Fr", "Ga", "Gd", "Ge", "H", "He", "Hf", "Hg", "Ho", "Hs", "I", "In", "Ir", "K", "Kr", "La", "Li", "Lr", "Lu", "Md", "Mg", "Mn", "Mo", "Mt", "N", "Na", "Nb", "Nd", "Ne", "Ni", "No", "Np", "O", "Os", "P", "Pa", "Pb", "Pd", "Pm", "Po", "Pr", "Pt", "Pu", "Ra", "Rb", "Re", "Rf", "Rg", "Rh", "Rn", "Ru", "S", "Sb", "Sc", "Se", "Sg", "Si", "Sm", "Sn", "Sr", "Ta", "Tb", "Tc", "Te", "Th", "Ti", "Tl", "Tm", "U", "Uub", "Uuh", "Uuo", "Uup", "Uuq", "Uus", "Uut", "W", "V", "Xe", "Y", "Yb", "Zn", "Zr" ] def find(cur, goal, sep=' + '): if (len(goal) == 0): # Got one! print(sep.join(cur)) return True ret = False for i in range(len(elements)): l = len(elements[i]) if l <= len(goal) and elements[i].upper() == goal[0:l].upper(): if find(cur + [elements[i]], goal[l:], sep): ret = True return ret if __name__ == '__main__': sys.argv.pop(0) if len(sys.argv) == 0: print("Usage: elwords.py word ...") sys.exit(1) for word in sys.argv: if not find([], word): print("Can't find an answer for %s." % word)