You will write a program that lists every formula of carbon, hydrogen and oxygen with a given nominal mass, and keeps only those with a sensible IHD.
The idea. For each number of carbon and oxygen atoms, the hydrogens are what is left of the mass. A formula is possible only if its IHD is a whole number and not negative.
Your tasks.
ihd(c, h) for a compound of C, H and O.possible(c, h). It returns True when h is at least 0 and the IHD is a whole number that is not negative.formulas(mass). It returns a list of (c, h, o) for 1 to 8 carbon atoms and 0 to 4 oxygen atoms.Run your code once to unlock the worked solution.
Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…