Closely related to Words from periodic table of elements (but that one is closed due to unclear specification?).
Closely related to Find the Chemistry of a name (probably a dupe, slightly different requirements though).
Closely related to [Br]eaking Code Golf [Ba]d (allows strings to be not expressible as solely a sequence of element abbreviations).
May I get a community consensus, whether this is better specified and/or sufficiently different to not be immediately closed as a dupe?
Elementize a string
Convert an input string to a concatenation of chemical element abbreviations.
Write a program/function/procedure etc. which will take as input a string/array of characters/pointer to a string etc. and return/print/display the same string expressed as a concatenation of chemical element abbreviations.
For example, takagi
can be expressed as TaKAgI
(i.e. the abbreviations for Tantalum(Ta), Potassium(K), Silver(Ag), Iodine(I)).
For this challenge you must use the following element name abbreviations:
{"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg",
"Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr",
"Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br",
"Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd",
"Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La",
"Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er",
"Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au",
"Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th",
"Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md",
"No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn"}
These are the elements with numbers 1 through 112. You may optionally also use the abbreviations for elements 113 through 118:
{"Nh", "Fl", "Mc", "Lv", "Ts", "Og"}
You may not, however, use the placeholder three-letter abbreviations for not yet named elements, such as "Uuo"
(Ununoctium).
If the input string cannot be expressed by the above abbreviations, you shall return one of the following:
- a falsey value (clearly distinct from element names, in other words
A
would not be valid, even though there is no element "A"; something like 0
, null
, false
, newline
is fine)
- an empty string
- exit without output
- exit with an error
- something similarly unambiguous signifying failure and not returning some incorrect output that could be accidentally misinterpreted as an answer (suggestions to make this specification clearer?)
Possible output, using example input takagi
:
- an appropriately capitalized string:
TaKAgI
.
- a flat array of characters
{"T", "a", "K", "A", "g", "I"}
with appropriate capitalization.
- a list of strings (capitalized or not) separated by newlines or as separate members of an array, etc., e.g.
ta \n k \n ag \n i
.
The rule of thumb is that the division into separate elements must be clear. Please comment if additional clarification is needed!
You may assume the input to be a single word consisting only of letters.
Compression is not the intent of this challenge! Boiler-plate code that fetches the list of elements from somewhere, hard-coding the lists of abbreviations, assuming the list of abbreviations to be stored in a variable or passed as a second argument to your function is OK and should not be included in the byte count.
Sample input -> sample output
no -> No // as in Nobelium, alternatively see next line
no -> NO // Nitrogen-Oxygen, either one is valid
helium -> falsey output
heliam -> HeLiAm
fog -> FOg // If using 118 elements, falsey otherwise.
ppcg -> falsey // I'm really, really sorry
Suggestions of further test cases are appreciated.
This is code-golf, shortest code wins.