[Community puzzle] Chemical Equation Balancing

Thanks for your help in finding it!

Now that I read this, I also remember another bug I hit (how many!) that only appeared randomly. I’m not solving with bruteforce by the way.

Basically, when calculating the equations and forming a matrix out of them, I had randomness in the row number they would appear. This does not influence the outcome theoretically, but can bite you the elimination process is not… careful enough.

So, you might want to try and balance K2PtCl4 + PPh3 + KOH + C2H5OH -> PtP4Ph12 + KCl + CH3CHO + H2O a few times and see if any error comes out of it (by the way, please note that this reaction contains the same element repeated multiple times inside the same molecule).

I get the same answer every time :
K2PtCl4 + 4PPh3 + 2KOH + C2H5OH -> PtP4Ph12 + 4KCl + CH3CHO + 2H2O
Maybe you have to sort your list of different elements once, so it doesn’t change from one execution to another ?

I removed the bug in the code so I’m not suffering from it any more. Anyway, even if your equations are always ordered deterministically, it might be that in the specific test they yield a combination that you don’t support?

I keep failing test 01. Still, when I test my code against hydrogen peroxyde, I get a correct :
2H2O2 -> 2H2O + O2

Any hint ?

What are the results of your other test cases and validators? Have you passed them all?

Yes, all of them. That’s why I am surprised.

Does your code work for AB + CD -> AC + BD?

Hi, I am struggling to pass the 7 validator ‘Copper and Ammonia’, however my code is able to solve the following equations: Cu(H2O)6 + NH3 -> Cu(NH3)4(H2O)2 + H2O; Cu(H2O)6 + NH3 -> Cu(H2O)4(OH)2 + NH4. Is there another copper and ammonia reaction that I am not aware of?

It looks like the answer is yes.
As said in statement, there is no parenthesis in the equation…

It is not needed to be a chemist to solve this puzzle but, without spoiling, copper is present here in an inorganic compound.

Yeah, involving parenthesis was my addition to this puzzle to test out other cases.

By inorganic compound, you mean something like Cu + NH3 + H2O -> CuOH + NH4? It is not valid, because it should be (OH)2, just an example though.

It is possible to solve the coeficients using equation system / matrix, but it is really not necessary as coeficients won’t be that big and a brute force / monte carlo approach will be enough.