Backstory
You wake up dizzy in a chemistry laboratory, and you realize you have been kidnapped by a old mad chemist. Since he cannot see very well because of his age, he wants you to work for him and only then, you can escape the laboratory.
Task
It is your task to return the structural formulae of the molecules whose chemical formula will be given as input. Note that only the carbon (C
), oxygen (O
) and hydrogen (H
) atoms will be used as input. Unlike in chemical formulas, a 0
is a valid quantifier and a 1
cannot be omitted (e.g. C1H4O0
is valid input, but CH4
isn't).
To prevent ambiguity, we assume double and triple bonds do not appear in the molecules. All carbon atoms need 4 single bonds, all oxygen atoms need 2, and hydrogen atoms need one. We also assume that O-O
bonds do not exist as well. The molecule does not have to exist nor be stable.
The input will never contain more than 3
carbon atoms to ensure lightness in the output's display.
You only should display the molecules whose carbons atoms are arranged in a straight line without interruption. Ergo, no C-O-C
bonds.
You must return all possible molecules not excluded by the previous rules. You do not need to handle invalid inputs.
The following example displays all the solutions you have to handle for that molecule.
A rotation by 180 degrees in the plane of the page of one of the molecule's formula is considered a redundancy and does not need to be displayed.
In the example below I'll show all of the possible formulae for a molecule, then point out the ones that do not need to be displayed.
Example
Input: C2H6O2
First, here are all the possible formulae for this input (Thank you to @Jonathan Allan)
01 H
|
O H
| |
H - O - C - C - H
| |
H H
02 H
|
H O
| |
H - O - C - C - H
| |
H H
03 H H
| |
H - O - C - C - O - H
| |
H H
04 H H
| |
H - O - C - C - H
| |
H O
|
H
05 H H
| |
H - O - C - C - H
| |
O H
|
H
12 H H
| |
O O
| |
H - C - C - H
| |
H H
13 H
|
O H
| |
H - C - C - O - H
| |
H H
14 H
|
O H
| |
H - C - C - H
| |
H O
|
H
15 H
|
O H
| |
H - C - C - H
| |
O H
|
H
23 H
|
H O
| |
H - C - C - O - H
| |
H H
24 H
|
H O
| |
H - C - C - H
| |
H O
|
H
25 H
|
H O
| |
H - C - C - H
| |
O H
|
H
34 H H
| |
H - C - C - O - H
| |
H O
|
H
35 H H
| |
H - C - C - O - H
| |
O H
|
H
45 H H
| |
H - C - C - H
| |
O O
| |
H H
And here are the formulae that should be in the output if we take out the rotations of 180° in the plane of the page :
01 H
|
O H
| |
H - O - C - C - H
| |
H H
03 H H
| |
H - O - C - C - O - H
| |
H H
12 H H
| |
O O
| |
H - C - C - H
| |
H H
13 H
|
O H
| |
H - C - C - O - H
| |
H H
14 H
|
O H
| |
H - C - C - H
| |
H O
|
H
15 H
|
O H
| |
H - C - C - H
| |
O H
|
H
23 H
|
H O
| |
H - C - C - O - H
| |
H H
25 H
|
H O
| |
H - C - C - H
| |
O H
|
H
35 H H
| |
H - C - C - O - H
| |
O H
|
H
You do not need to output the labels of the formulae and you can output either of the rotations when two exist. For example you can output either 02 or 35.
Here are some valid inputs to test your code:
C3H8O2 C1H4O0 C2H6O2 C1H4O1 C2H6O2
The PC the chemist gave you to complete your task is quite old so you do not have a lot of memory on it to save your code, thus this is code-golf and the shortest amount of byte wins!