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 step.
You can see that with the combustion of any alkane, oxygen is used. After the reaction, only CO2 and H2O are made.
Give a complete program that takes input from STDIN or the nearest possible equivalent, and outputs the total reaction using STDOUT or the nearest possible equivalent.
The input will always be in the form
n > 0. These are some example inputs:
CH4 C2H6 C3H8 C4H10 C5H12 C6H14 etc.
A useful tip:
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
input: CH4 output: 2CH4 + 4O2 > 4H2O + 2CO2 input: C3H8 output: 2C3H8 + 10O2 > 8H2O + 6CO2 input: C4H10 output: 2C4H10 + 13O2 > 10H2O + 8CO2 input: C12H26 output: 2C12H26 + 37O2 > 26H2O + 24CO2
- You need to provide a full program.
- Your program needs to take input from STDIN, or the nearest equivalent if not possible.
- Your program needs to output using STDOUT, or the nearest equivalent if not possible.
- 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!