It is bad practice to draw out your molecules in 2 dimensions because that is not how they are. I chose to do this in 2D because it is easier to explain.
Note that the bond angles are wrong too: the angle in CH4 is 109.5°, not 90° as I said and the bond angle in NH4 is 107°. BHCl2 does have a bond angle of 120° and is 2D, however.
Given the formula of a simple molecule as input, output a truthy value if the molecule is polar (asymmetrical) or a falsey value if the molecule is non-polar (symmetrical).
To determine whether a molecule is polar or not, we will have to look at its shape. For the purposes of this challenge, we will assume that molecules are 2D.
To demonstrate how to determine the polarity of a molecule, let us use three examples: methane (CH4), ammonia (NH3) and BHCl2.
Firstly, lets take the centre molecule, carbon. Carbon is in group four of the periodic table so it has four outer shell electrons, as shown below:
Now, we add the hydrogen atoms (each hydrogen atom supplies its own electron to make a pair):
Since there are no lone pairs of electrons, we can draw it with 90° between each bond since all bonds repel equally:
We can now see that methane is symmetrical so it is non-polar.
Like above, we take the centre molecule, nitrogen and draw out its outer shell electrons:
Adding the hydrogen atoms, we notice that there is a lone pair of electrons:
Since the lone pair is closer to the atom, it repels more than a bonding pair, so the angle between the bonds is smaller:
Evidently, NH3 is not symmetrical, so it is polar.
Taking boron as the centre molecule, we draw the three outer electrons:
We then add the hydrogen and the chlorines:
There are no lone pairs, so the bonds repel equally, forming an angle of 120°:
Although, the shape is symmetrical, the hydrogen atom makes the molecule asymmetrical, so BHCl2 is polar.
Built-ins which access molecule information are disallowed. You may access periodic table data using built-ins or without adding the file to your byte count. This data may be stored however you wish.
Input will only ever be a valid simple molecule: a single central atom (p-block element) which comes first in the formula and up to eight outer atoms (hydrogen, fluorine, chlorine, bromine, iodine, astatine) which only use single bonds.
You will never get a polyatomic ion or a molecule with co-ordinate (dative covalent) bonds as input. For example, with
NH4, there would be a single unpaired electron, so the only for NH4 to form a stable molecule would be to lose the extra electron and become an ion (a polyatomic ion, since there is more than one atom in the ion).
If there are multiple lone pairs, they have to be spaced as far as possible from each other. For example, two lone pairs will have to be opposite from each other.
If there are non-polar and polar isomers of a molecule (e.g. SiF2Cl2) you should assume the molecule is non-polar.
Input -> Output OH2 -> Falsey CCl4 -> Falsey OF4 -> Truthy CH4 -> Falsey NH3 -> Truthy BHCl2 -> Truthy
Shortest code in bytes wins.