The resulting polymer isn’t nearly strong enough to reinforce the submarine. You’ll need to run more steps of the pair insertion process; a total of 40 steps should do it.
In the above example, the most common element is B
(occurring 2192039569602
times) and the least common element is H
(occurring 3849876073
times); subtracting these produces 2188189693529
.
Apply 40 steps of pair insertion to the polymer template and find the most and least common elements in the result. What do you get if you take the quantity of the most common element and subtract the quantity of the least common element? Determine this in the following way:
polymerize
that takes the pathname (str
) of a text file containing a polymer template and a list of pair insertion rules. The function must return the quantity of the most common element minus the quantity of the least common elements (int
) after 40 steps of pair insertion to the polymer template.In this interactive session we assume the text files rules01.txt
1 and rules02.txt
2 to be located in the current directory.
>>> polymerize('rules01.txt')
2188189693529
>>> polymerize('rules02.txt')
8336623059567
Nazarii Bardiuk (@nbardiuk3) animated his solution.