Consider the following string:
Tin Snips
This string contains several atomic symbols on the periodic table. We could rewrite this string to identify several of them:
[Ti][N] [Sn][I][P][S]
Of course, we could also write it this way:
T[In] [S][Ni][P][S]
The rules for rewriting the input are as follows:
- The case of the input does not matter in terms of matching atomic symbols.
- If an element is used in an atomic symbol, its case must change so the symbol is correct. Ex:
h
would become[H]
. - All element symbols are encased in ASCII square brackets,
[
and]
. - Whitespace is preserved:
Big ego
cannot combine the "g" and "e" into[Ge]
. - Not all input characters need be combined into an atomic symbol: if an input character is not put into a symbol, it is passed through as-is (case does not matter).
- If a symbol can be made, it must be made. In other words, it is not allowed to output
Tin
in the above example because it is possible to create at least one symbol in that word. The only time a character may be passed through unused is when it cannot be used to construct an atomic symbol. - For the purposes of this challenge, all elements from Hydrogen (1) to Oganesson (118) are valid. No higher elements are valid.
- Some of the higher elements have ambiguous names and symbols: for the purposes of this challenge, the version at Wikipedia shall be used. For convenience, the allowable atomic symbols are here: 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, Nh, Fl, Mc, Lv, Ts, Og.
Write a program or function that generates all possible outputs from a single provided input. Both input and output may be in any form of your choosing. This could be a string, array of characters, or some other data structure: whatever is both convenient and clearly represents the input and output. Both input and output may be passed in/out of your code however you choose: standard in/out, function argument/return, or something else.
- Input shall be a string (see previous paragraph) of positive length containing only ASCII characters of arbitrary case and the space (
0x20
) character. - Your code must generate all output strings that can be created using the input rules above.
- The order of the output is implementation-defined. The only requirement is that all output strings are present.
- If presented with a valid input string that does not contain any atomic symbols, simply output the input string.
- If presented with an input string that is not valid per the rules above (null, zero characters, contains illegal characters, etc.) your program may do anything (crash, blank output, etc.)
- Output is case-insensitive other than atomic symbols needing to match the periodic table.
- Standard loopholes not allowed.
Test cases:
Tin Snips
[Ti][N] [Sn][I][P][S]
[Ti][N] [S][Ni][P][S]
[Ti][N] [S][N][I][P][S]
T[In] [Sn][I][P][S]
T[In] [S][Ni][P][S]
T[In] [S][N][I][P][S]
T[I][N] ...
Quack
Q[U][Ac][K]
Q[U]a[C][K]
hehe
[H]e[H]e
[H]e[He]
[He][H]e
[He][He]
Stack Exchange
[S][Ta][C][K] Ex[C][H]a[N][Ge]
[S]t[Ac][K] Ex[C][H]a[N][Ge]
This is code golf, so let me see your shortest code!
T[I][N]
not[T][I][N]
because T is not an element. My question (and possibly Rassar's) is: do we only have to give 1. Only outputs where the maximium number of element subsitutions are made? 2. Only the minimum amount of wastage? (The HeHe with hydrogens indicates the answer to this one is no) 3. All outputs where matches are completely exhausted? (in this caseT[I][N]
as well asT[In]
would be valid.) I think the correct interpretation is 3. \$\endgroup\$Q[U][Ac][K]
andQ[U]a[C][K]
. RIght? \$\endgroup\$