Corresponding with Gottfried Leibniz1 about his method of infinite series in 1677, Isaac Newton2 wanted to advert to his "fluxional method" — the calculus — without actually revealing it. So he used an unusual expedient — after describing his methods of tangents and handling maxima and minima, he added:
The foundations of these operations is evident enough, in fact; but because I cannot proceed with the explanation of it now, I have preferred to conceal it thus: 6accdae13eff7i3l9n4o4qrr4s8t12ux. On this foundation I have also tried to simplify the theories which concern the squaring of curves, and I have arrived at certain general Theorems.
That peculiar string (marked in green) is an inventory of the letters in the phrase that Newton wanted to conceal
Data aequatione quotcunque fluentes quantitates involvente, fluxiones invenire; et vice versa.
which means
Given an equation involving any number of fluent quantities3 (functions) to find the fluxions4 (derivatives), and vice versa.
So 6a indicates that the Latin phrase contains six instances of the letter a, cc means the letter c appears twice, and so on. In this way Newton could register his discovery without actually revealing it — the fact that he could present an accurate letter inventory of the fundamental theorem of the calculus proved that he had established the theorem before the date his letter was sent.
The inventory of a sentence indicates how often each letter of the alphabet appears in it: first the number of times the letter a appears, then the number of times the letter b appears, and so on. The inventory encodes the number of occurrences $$n$$ of a letter $$\alpha$$ in the following way:
$$n\alpha$$ if the letter $$\alpha$$ appears at least three times ($$n \geq 3$$)
$$\alpha\alpha$$ if the letter $$\alpha$$ appears only twice ($$n = 2$$)
$$\alpha$$ if the letter $$\alpha$$ appears only once ($$n = 1$$)
nothing if the letter $$\alpha$$ does not appear at all ($$n = 0$$)
When counting occurrences, no distinction is made between uppercase and lowercase letters. The inventory always denotes letters in lowercase. All encodings for successive letters of the alphabet are written one after the other in the inventory. Occurrences of characters that are not letters, are not recorded in the inventory.
Your task:
Write a function inventory that takes a sentence (str) and returns its inventory (str).
Write a function unpack that takes a sentence (str) and returns the unpacked sentence (str). This is the sentence in which each occurrence of a number $$n$$ (a sequence of digits) followed by a non-digit character $$c$$ was replaced by $$n$$ repetitions of character $$c$$. For example, 6a is replaced by aaaaaa. All non-digit characters not preceded by a number in the original sentence should simply remain in place in the unpacked sentence.
Write a function simplify that takes a sentence (str) and returns the inventory (str) of the unpacked sentence.
>>> inventory('Data aequatione quotcunque fluentes quantitates involvente, fluxiones invenire; et vice versa.')
'7accd14eff7i3l9n4o4qrr4s9t7u5vx'
>>> inventory('ut tensio sic vis')
'ce3ino3sttuv'
>>> unpack('6accdae13eff7i3l9n4o4qrr4s8t12ux')
'aaaaaaccdaeeeeeeeeeeeeeeffiiiiiiilllnnnnnnnnnooooqqqqrrssssttttttttuuuuuuuuuuuux'
>>> unpack('ce3ino3sttuv')
'ceiiinosssttuv'
>>> simplify('6accdae13eff7i3l9n4o4qrr4s8t12ux')
'7accd14eff7i3l9n4o4qrr4s8t12ux'
>>> simplify('i2scvotu2ietns')
'ce3ino3sttuv'
The idea of timestamping information is centuries old. For example, when Robert Hooke8 discovered Hooke's law9 in 1660, he did not want to publish it yet, but wanted to be able to claim priority. So he published the anagram ceiiinosssttuv and later published the translation ut tensio sic vis (Latin for "as is the extension, so is the force"). Similarly, Galileo Galilei10 first published his discovery of the phases of Venus in the anagram form. The technique today is known as trusted timestamping11.
How a book written in 1910 could teach you the basic principle∫ of calculus better than many of the modern textbooks.