How many atoms in the hydrocarbon?
A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.
An alkane with \$n\$ carbon atoms contains \$2n+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \$2n\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \$2n-2\$ hydrogen atoms.
Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix
yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:
1 <-> meth 2 <-> eth 3 <-> prop 4 <-> but 5 <-> pent 6 <-> hex 7 <-> hept 8 <-> oct 9 <-> non 10 <-> dec
For example, we can see
propane has 3 carbon and 8 hydrogen atoms, and
heptyne has 7 carbon and 12 hydrogen atoms.
Your task is to write a function or program that receives a string or list of characters representing the name of a hydrocarbon, and produces or outputs the number of carbon and hydrogen atoms in a molecule of that hydrocarbon.
For each of the 30 hydrocarbon names, the code must accept at least one possible capitalization of that name. For example, it is fine if your code works for
mEthane but not
ETHAnE but not
Propane but not
propane. The inputs
methyne may give undefined output since those are not real chemicals.
The input and output can be in any convenient format. You don't need to label which number represents carbon and which represents hydrogen, just keep the order of the numbers consistent.
You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.
Possible Input -> Possible Output Methane -> 1 4 propane -> 3 8 Heptyne -> 7 12 Decene -> 10 20
- No standard loopholes.
- Shortest code in bytes wins.