+ 1
Handling Edge Cases
https://sololearn.com/compiler-playground/WW1HMgOU5Nno/?ref=app Can someone help me make sure that the computer can point out chemically invalid reactions. Test case– Input: Fe2O3 + Al -> AlO + FeAl Output: Fe2O3 + 5Al → 3AlO + 2FeAl This is chemically invalid (two metals Fe and Al can NEVER combine to form compounds).
4 Respuestas
+ 1
I see you're using regex in there. Couldn't you just regex to see if some kind of invalid mix occurs?
You could maybe create a list of invalid combos, maybe even a dictionary, if they are always pairs...
0
Ausgrindtube , could you please elaborate?
You see, errors can be of innumerable types, and there are tends-to-∞ chemical reactions thereby making it nearly impossible to create a dictionary of them...
0
I'm not a chemical scientist and it's been like 30 years since I was in school doing chemistry, so excuse my ignorance.
What I was thinking: if you identify in either half of your equation, in your example: Fe or Al, which you could do with regex, then, you could run it through a loop looking for any possible invalid mix, as soon as it finds this, it can stop and output that its invalid.
Yeah, you'll have to create a list of all possible elements and then another list or multiple lists of invalid options.
I don't think there's any easier way* - it's not like a program can think for itself and know what's invalid.
*there are way smarter people here than I am. Maybe they'll find your thread and offer their opinions.
You can also search the code playground, the forum or places like github for maybe similar approaches.
https://www.sololearn.com/discuss/2337875/?ref=app
https://www.sololearn.com/discuss/3173656/?ref=app
Here's what I found with edge cases... perhaps not the best subject heading.
0
Ausgrindtube , thank you.
I guess, lets just hope that the user will enter a chemically valid equation...