#chemistryyyyyyy
1 messages · Page 1 of 1 (latest)
So, let's say we have 2Na + 2H2O -> 2NaOH + H2
I want to calculate mass (won't get into that)
also it seems people aren't in the habit of using threads
But what I need is the coefficients.
alright
I can calculate NaOHs mass easily since both NaOH and Na has a coefficient
If I want to calculate the mass of Hydrogen however, that's trickier.
provided that the format gets followed
I would think that you could iterate through the string until it reaches the -> character
Wouldn’t it be just 2 since its 2 hydrogens?
and extract every different element
I need to divide it by the amount of coefficients in 2H2O, so in this case: 2.
No. If you have 2 in the beggining you need to multiply that by the amount of atoms.
hm.
Yes, but I was just talking about hydrogen here
ah wait thats how it works?
Yes
I’m in my chemistry class right now :)
been a while since ive done chemistry
Yes
so
2H2O -> Four Hydrogens, Two Oxygen atoms
2H2O2 is 4 hydrogens 4 oxygens
you should use spaces as delimiters, right?
so to clear it up, the first number (if there is one) denotes that you need to multiply subsequent numbers of the elements by that first number right?
ah i understand now
and for every molecule, just check the first character for the coefficient
Parentheses are usually what it is
every subsequent number in the molecule will multiply the element that came prior
spaces as a delimiter to isolate every molecule
so 2H2O would be 4 hydrogen 2 oxygen right?
Yes
Also, so we don't get off the track
I simply want to do something like this: check if the compounds I need to use have the coefficients, if not, divide by the amount of coefficients from, say 2H2O
Ugh hold on my wording is confusing
Na: 2
H2O: 2
NaOH: 2
H2: 0
if one of them is zero
divide by the amount of another compound that is being used to calculate the mass of the product
But I will take it from here I guess since I received the answer - use a parser and check for capital letters
pretty much
check if the first char of each compound is a number, then based on that you can record it down how you need
if AFTER the first char theres any number occurrences, you associate the number with the element that was in the previous char/string/whatever
Yup
question
hm?
are you planning on creating an object that stores each element + how many of them are present
I don't believe that
I'm using a dictionary at the moment
an array of molecule structs, and in that struct, an element and # of instances
but then again, I'm still resident of #💻┃code-beginner
I'm not really an expert on data structures
any, gl with your parser