Consider the following string:
This string contains several atomic symbols on the periodic table. We could rewrite this string to identify several of them:
Of course, we could also write it this way:
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:
- All element symbols are encased in ASCII square brackets,
- Whitespace is preserved:
Big egocannot combine the "g" and "e" into
- 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
Tinin 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 (
- 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.
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!