What's special about these word chains?
man, main, margin, marginal
loon, lotion, location, allocation, reallocation
art, cart, chart, charter, character, characters
rig, ring, raging, ranging, arranging, rearranging, prearranging
The next word in each chain is formed by inserting the symbolic name (blue text) of a chemical element at a particular position (marked by a blue square: ■) into the previous word.
ma■n + I (iodine) → ma■in + Rg (roentgenium) → margin■ + Al (aluminum) → marginal
lo■on + Ti (titanium) → lo■tion + Ca (calcium) → ■location + Al (aluminum) → ■allocation + Re (rhenium) → reallocation
■art + C (carbon) → c■art + H (hydrogen) → chart■ + Er (erbium) → char■ter + Ac (actinium) → character■ + S (sulfur) → characters
ri■g + N (nitrogen) → r■ing + Ag (silver) → ra■ging + N (nitrogen) → ■ranging + Ar (argon) → ■arranging + Re (rhenium) → ■rearranging + P (phosphorus) → prearranging
A substance is a unique form of matter with constant chemical composition and characteristic properties — a chemically pure substance. Substances may consist of atoms of a single chemical element or atoms of two or more elements (compounds).
A chemical reaction is a process that leads to the transformation of one set of substances (e.g. $$A$$, $$B$$ and $$C$$) to another set of substances (e.g. $$D$$ and $$E$$) \[ A + B + C \longrightarrow D + E \] The substances initially involved in a chemical reaction are called reactants ($$A$$, $$B$$ and $$C$$ in the example). Chemical reactions yield one or more products ($$D$$ and $$E$$ in the example), which usually have properties different from the reactants.
Synthesis is a reaction where a more complex substance is formed. Decomposition is a reaction where a substance breaks down.
An elementary reaction is the smallest division into which a chemical reaction can be decomposed. It has no intermediate products. Most experimentally observed reactions are built up from many elementary reactions that occur in parallel or sequentially.
We represent a chemical substance as a sequence of letters (str): both uppercase and lowercase letters are allowed. We work with elementary synthesis reactions that bind a substance (reactant) and one atom of a chemical element (atom) into a new substance (product)
reactant + atom → product
We also work with elementary decomposition reactions that break down a substance (reactant) into a new substance (product) and one atom of a chemical element (atom)
reactant → product + atom
Elementary synthesis and decomposition are thus counterparts of each other. In both cases, we ensure that the reactant and the product are existing English words (str) and that the atom is represented by the symbolic name (str) of a chemical element. That name consists of one or two letters (usually represented as an uppercase letter, possibly followed by a lowercase letter). An elementary synthesis reaction inserts the symbolic name of an atom at some position (marked by ■; front, back or somewhere in the middle) between the letters of the reactant. As such, we may get
dea■n + Fe → deaFen
An elementary decomposition reaction removes the symbolic name of an atom at some position (■) from the letters of the reactant. As such, we may get
merCury → mer■ry + Cu
Your task:
Write a function synthesis that takes two strings (str): i) a reactant and ii) the symbolic name of an atom. The function should return a list of all possible products (str; in lowercase) that may result from an elementary synthesis reaction of the reactant and the atom. The products should be listed according to the position (from left to right) where the symbolic name of the atom is inserted before, between or after the letters of the reactant. There is no need to check whether these products are existing words.
Write a function decomposition that takes two strings (str): i) the reactant and ii) the product of an elementary decomposition reaction. The function should return the result (product and atom) of the decomposition reaction as a tuple with two strings (str):
the product: the reactant from which the symbolic name of the atom was removed at a position denoted by a square (■) and otherwise preserves the remaining uppercase and lowercase letters as they occur in the reactant
the atom: the symbolic name removed from the reactant, represented as an uppercase letter that may be followed by a lowercase letter
When searching for the symbolic name to be removed from the reactant to yield the product, no distinction should be made between uppercase and lowercase letters in the reactant and the product. The function may assume that the decomposition reaction can only occur in one possible way, without having to check this explicitly.
Write a function atoms that takes a sequence (list or tuple) containing the initial reactant and the successive (intermediate) products of a reaction consisting of a number of successive elementary decomposition reactions. However, those substances should not necessarily be listed in the order in which they occur in the successive stages of the reaction. The function should return a list containing the symbolic names (str) of the atoms removed in the successive elementary decomposition reactions (listed in that order). Each symbolic name should be represented as an uppercase letter, possibly followed by a lowercase letter. When searching for the symbolic name to be removed from a reactant to yield the next product, no distinction should be made between uppercase and lowercase letters in the reactant and the product. The function may assume that each of the successive elementary decomposition reactions can only occur in one possible way, without having to check this explicitly.
Because one atom (symbolic name) is lost in each successive elementary decomposition reaction, the chain reaction yields a sequence of substances (words) that get shorter and shorter. This way, you can reconstruct the order in which the substances (words) occur in the successive stages of the reaction.
Write a function products that takes two arguments: i) a reactant (str) from a decomposition reaction, and ii) a sequence (list or tuple) containing the symbolic names (str) of the atoms removed in the successive elementary decomposition reactions (in the order in which they were removed). The function should return a list containing the reactant (str) and the (intermediate) products (str) that occur in the successive elementary decomposition reactions (listed in that order). In removing the symbolic name of an atom, no distinction should be made between upper and lower case letters, but the product must preserve the remaining uppercase and lowercase letters as they occur in the reactant. It is possible for the symbolic name of an atom to appear more than once in a reactant. If all letters of a given symbolic name are uppercase, then its last occurrence must be removed. Otherwise, its first occurrence must be removed.
>>> synthesis('dean', 'Fe')
['fedean', 'dfeean', 'defean', 'deafen', 'deanfe']
>>> synthesis('Merry', 'Cu')
['cumerry', 'mcuerry', 'mecurry', 'mercury', 'merrcuy', 'merrycu']
>>> synthesis('FOREST', 'Ca')
['caforest', 'fcaorest', 'focarest', 'forcaest', 'forecast', 'forescat', 'forestca']
>>> synthesis('rAiNStORM', 'B')
['brainstorm', 'rbainstorm', 'rabinstorm', 'raibnstorm', 'rainbstorm', 'rainsbtorm', 'rainstborm', 'rainstobrm', 'rainstorbm', 'rainstormb']
>>> decomposition('deafen', 'dean')
('dea■n', 'Fe')
>>> decomposition('Mercury', 'Merry')
('Mer■ry', 'Cu')
>>> decomposition('FORECAST', 'FOREST')
('FORE■ST', 'Ca')
>>> decomposition('BrAiNsToRm', 'RaInStOrM')
('■rAiNsToRm', 'B')
>>> atoms(['margin', 'man', 'marginal', 'main'])
['Al', 'Rg', 'I']
>>> atoms(('Loon', 'Allocation', 'Reallocation', 'Lotion', 'Location'))
['Re', 'Al', 'Ca', 'Ti']
>>> atoms(['CART', 'CHARTER', 'CHARACTER', 'CHARACTERS', 'ART', 'CHART'])
['S', 'Ac', 'Er', 'H', 'C']
>>> atoms(('rANgING', 'raGiNg', 'Arranging', 'RiG', 'ReARranGINg', 'PrEarraNgING', 'riNG'))
['P', 'Re', 'Ar', 'N', 'Ag', 'N']
>>> products('marginal', ['aL', 'rG', 'I'])
['marginal', 'margin', 'main', 'man']
>>> products('Reallocation', ('RE', 'aL', 'CA', 'Ti'))
['Reallocation', 'allocation', 'location', 'lotion', 'loon']
>>> products('CHARACTERS', ['S', 'ac', 'ER', 'H', 'c'])
['CHARACTERS', 'CHARACTER', 'CHARTER', 'CHART', 'CART', 'ART']
>>> products('PreARrANginG', ('p', 'rE', 'aR', 'n', 'AG', 'N'))
['PreARrANginG', 'reARrANginG', 'ARrANginG', 'rANginG', 'rAginG', 'rinG', 'riG']
What killed Edgar Allan Poe1?
On Oct. 3, 1849, Poe was found on the streets of Baltimore, delirious and wearing clothes that were not his own. The man who found him said he was
in great distress, and … in need of immediate assistance.
He remained incoherent and died four days later. He was only 40.
An acquaintance said it was drunkenness, but he turned out to be a supporter of the temperance movement who distorted the facts. The attending physician wrote that
… Edgar Allan Poe did not die under the effect of any intoxicant, nor was the smell of liquor upon his breath or person.
Well, what, then? Other theories include a rare brain disease, diabetes, iron deficiency, syphilis, even rabies. One theory dating from 1872 suggests that Poe's death resulted from cooping2, a form of electoral fraud in which citizens were forced to vote for a particular candidate, sometimes leading to violence and even murder.
There's no surviving death certificate, so we'll never really know. Today Poe lies in the churchyard at Westminster Presbyterian Church3 in Baltimore, where mystery follows him even in death: every year since 1949, the grave has been visited by a mystery man in the early hours of the poet's birthday, Jan. 19. Dressed in black and carrying a silver-tipped cane, the Poe Toaster4 kneels at the grave and makes a toast with Martell cognac5. He leaves behind the half-empty bottle and three red roses. Several of the cognac bottles are kept at the Edgar Allan Poe House and Museum6 in Baltimore.