Difference between revisions of "Chemical Calculator"

From Fōrmulæ wiki
Jump to: navigation, search
(Preamble)
Line 32: Line 32:
  
 
[[File:ChemicalCalculatorPreamble4.png|border]]
 
[[File:ChemicalCalculatorPreamble4.png|border]]
 +
 +
[[File:ChemicalCalculatorPreamble5.png|border]]
 +
 +
[[File:ChemicalCalculatorPreamble6.png|border]]
  
 
==== Solution ====
 
==== Solution ====

Revision as of 20:25, 21 March 2019

This page is the answer to the task Chemical Calculator in the Rosetta Code.

Description (from Rosetta Code)

Given a molecule's chemical formula, calculate the molar mass.

Introduction

  • A molecule consists of atoms. E.g. water, H2O, has two hydrogen atoms and one oxygen atom
  • The mass of H2O is 1.008 * 2 + 15.999 = 18.015
  • An atom name consists of one upper-case letter followed by zero, one or two lower-case letters.
    • H (Hydrogen)
    • He (Helium)
    • Uue (Ununennium)
  • The number of atoms is stated behind the atom or atom group
  • An atom group is specified using parenthesis. E.g. Butyric acid, (CH3)2CHCOOH, has two CH3 groups
  • A group may contain other groups, e.g. COOH(C(CH3)2)3CH3

Link

Molecular mass

Answer

Preamble

ChemicalCalculatorPreamble1.png

ChemicalCalculatorPreamble2.png

ChemicalCalculatorPreamble3.png

ChemicalCalculatorPreamble4.png

ChemicalCalculatorPreamble5.png

ChemicalCalculatorPreamble6.png

Solution

ChemicalCalculatorCode.png

Use cases

ChemicalCalculatorOutput1.png

Other examples

ChemicalCalculatorOther1.png

ChemicalCalculatorOther2.png

ChemicalCalculatorOther3.png

ChemicalCalculatorOther4.png

ChemicalCalculatorOther5.png