One of the first things I learned in chemistry, was giving the formula for the combustion of alkanes. The most basic example was:
2CH4 + 4O2 -> 4H2O + 2CO2. Note that the equation could have been simplified by dividing every coefficient by 2, we would get
CH4 + 2O2 -> 2H2O + CO2. To make things easier, we are going to ignore this to not complicate things.
You can see that with the combustion of any alkane, oxygen is used. After the reaction, only
H2O are made.
The input will always be in the form
n>0. These are some example inputs:
CH4 C2H6 C3H8 C4H10 C5H12 C6H14
Every alkane has a standard pattern in the combustion reaction:
2C(n)H(2n+2) + (3n+1)O2 -> (2n+2)H2O + (2n)CO2
C4H10 gives the following equation:
2C(4)H(2*4+2) + (3*4+1)O2 -> (2*4+2)H2O + (2*4)CO2. After calculating everything, we get this final equation
2C4H10 + 13O2 -> 10H2O + 8CO2
CH4 2CH4 + 4O2 -> 4H2O + 2CO2 C3H8 2C3H8 + 10O2 -> 8H2O + 6CO2 C4H10 2C4H10 + 13O2 -> 10H2O + 8CO2 C12H26 2C12H26 + 37O2 -> 26H2O + 24CO2
- Note that I used spaces for the examples to increase readability, these are not necessary.
2CH4 + 4O2 -> 4H2O + 2CO2and
2CH4+4O2->4H2O+2CO2are both valid outputs. However, if you consistently use spaces for the output, you get a -10% bonus
- This is code-golf, so the program with the least amount of bytes wins!