Naming ionic compounds An ionic compound is named like so: (metal name) (non-metal suffixed with -ide). Here is a list of all the suffixes that need to be replaced with -ide:

-on -ogen -ygen -ine -orus -ur -ic -ium


The number of atoms of each element in the compound is not used in naming ionic compounds. Ignore the multivalent metal naming rules.

NaCl -&gt; sodium + chlorine -&gt; sodium chloride.
K2S -&gt; potassium + sulphur -&gt; potassium sulphide (or sulfide).
Yb2P3 -&gt; ytterbium + phosphorus -&gt; ytterbium phosphide.
PbTe2 -&gt; lead + tellurium -&gt; lead telluride.


A string containing an ionic compound (NaCl, K2S, Yb2P3) will be given as input. No polyatomic ions will be given. The program has to output the name of this compound.

Since nobody wants to compile the periodic table data themselves, here is a paste that has the names, symbols, and whether or not it is a metal of each element, in this order: (name) (symbol) (is metal?). You can save this to an external file (the length of the file will not be counted), or you can store the data within your program (just discount the length of that string from there.) You may not need all the information provided. Every element is seperated by a newline.

As always with code golf challenges, shortest code wins.
Ruby, 114

f,s=$*[0].split /\d*(?=[A-Z]|\Z)/
puts (n=Hash[*&lt;&lt;X.split-%w[0 1]].invert)[f]+" "+n[s].sub(/(i..|.gen|..)\Z/,"ide")
Hydrogen H 0
Helium He 0
Lithium Li 1
Beryllium Be 1
Boron B 0
Carbon C 0
Nitrogen N 0
Oxygen O 0
Fluorine F 0
Neon Ne 0
Sodium Na 1
Magnesium Mg 1
Aluminium Al 1
Silicon Si 0
Phosphorus P 0
Sulfur S 0
Chlorine Cl 0
Argon Ar 0
Potassium K 1
Calcium Ca 1
Scandium Sc 1
Titanium Ti 1
Vanadium V 1
Chromium Cr 1
Manganese Mn 1
Iron Fe 1
Cobalt Co 1
Nickel Ni 1
Copper Cu 1
Zinc Zn 1
Gallium Ga 1
Germanium Ge 1
Arsenic As 0
Selenium Se 0
Bromine Br 0
Krypton Kr 0
Rubidium Rb 1
X


Uses a paste of the element text that I haven't counted in the score. I remove the metal tag (since I'm assuming the compounds are always given with the metal first, so I don't actually need it) and build a dictionary with it. I identify the part to replace with "ide" by checking the end of the string for three letters starting with i, four letters ending with gen, or otherwise just the last two characters.