#chemistryyyyyyy

1 messages · Page 1 of 1 (latest)

rigid mango
#

so, what was the problem again?

#

being able to identify when a coefficient is 1?

winter bough
#

So, let's say we have 2Na + 2H2O -> 2NaOH + H2

#

I want to calculate mass (won't get into that)

rigid mango
#

also it seems people aren't in the habit of using threads

winter bough
#

But what I need is the coefficients.

rigid mango
#

alright

winter bough
#

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.

rigid mango
#

provided that the format gets followed

#

I would think that you could iterate through the string until it reaches the -> character

visual cipher
rigid mango
#

and extract every different element

winter bough
#

I need to divide it by the amount of coefficients in 2H2O, so in this case: 2.

winter bough
rigid mango
#

hm.

winter bough
#

Aka in 2H2O you have 4 hydrogens

#

H2O - two

rigid mango
#

bro I forgot that

#

I thought 2H2O meant 2H, 2O

visual cipher
#

No

#

It multiplies everything

rigid mango
#

for sure?

#

like

winter bough
#

Yes, but I was just talking about hydrogen here

solid gyro
#

ah wait thats how it works?

winter bough
#

Yes

visual cipher
solid gyro
#

been a while since ive done chemistry

visual cipher
#

Yes

rigid mango
#

so

winter bough
#

2H2O -> Four Hydrogens, Two Oxygen atoms

visual cipher
#

2H2O2 is 4 hydrogens 4 oxygens

rigid mango
#

you should use spaces as delimiters, right?

solid gyro
#

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

rigid mango
#

and for every molecule, just check the first character for the coefficient

visual cipher
rigid mango
#

every subsequent number in the molecule will multiply the element that came prior

rigid mango
solid gyro
#

so 2H2O would be 4 hydrogen 2 oxygen right?

winter bough
#

Yes

solid gyro
#

I see

#

so heres what you should prob do

winter bough
#

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

solid gyro
#

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

winter bough
#

Yup

rigid mango
#

question

winter bough
#

hm?

rigid mango
#

are you planning on creating an object that stores each element + how many of them are present

winter bough
#

that was my original idea but got told it was

#

well

#

not going to work

rigid mango
#

I don't believe that

winter bough
rigid mango
#

an array of molecule structs, and in that struct, an element and # of instances

#

I'm not really an expert on data structures

#

any, gl with your parser