The 15th-century Venetian navigator Alvise Cadamosto describes a curious convention by which the Mauritanian Azanaghi traded salt with the merchants of Mali:

All Mauritanians who have salt pile it in rows, each marking their own. Having made these piles, the whole caravan retires half a day’s journey. Then there comes the Malians who do not wish to be seen or to speak. They arrive in large boats, from which it appears that they come from islands, and disembark. Seeing the salt, they place a large quantity of gold opposite each pile, and then turn back, leaving salt and gold. When they have gone, the Mauretanians return: if they are satisfied with the quantity of gold, they leave the salt and retire with the gold. Then the Malians return, and remove those piles which are without gold. By the other piles of salt they place more gold, if it pleases them, or else they leave the salt. In this way, by long and ancient custom, they carry on their trade without seeing or speaking to each other.

In this way different cultures can trade safely without speaking the same language. It's called the silent trade1. Herodotus2 describes a similar practice between Carthage and West Africa, and it's been reported also in Siberia, Lapland, Timor, Sumatra, India, Sri Lanka, and New Guinea.

Why didn't the Malians simply take the salt? Presumably because trade was more valuable to them in the long run. I wonder how such a custom gets started in the first place, though.

Assignment

We represent a pile of salt and gold as a string (str) in which each hash (#) represents one amount of salt and each digit an amount of gold corresponding in size to the digit: the digit 3 for example represents three amounts of gold. All other characters in the string are neither salt nor gold. Your task:

Example

>>> salt('gj1h##hg3ur#zt#zhg#e#2h##jgs#kjl')
9
>>> salt('gj2h##hg7ur#zt#zhg#e#5h##jgs#kjl')
9

>>> gold('gj1h##hg3ur#zt#zhg#e#2h##jgs#kjl')
6
>>> gold('gj2h##hg7ur#zt#zhg#e#5h##jgs#kjl')
14

>>> remove_salt('gj1h##hg3ur#zt#zhg#e#2h##jgs#kjl')
'gj1hhg3urztzhge2hjgskjl'
>>> remove_salt('gj2h##hg7ur#zt#zhg#e#5h##jgs#kjl')
'gj2hhg7urztzhge5hjgskjl'

>>> remove_gold('gj1h##hg3ur#zt#zhg#e#2h##jgs#kjl')
'gjh##hgur#zt#zhg#e#h##jgs#kjl'
>>> remove_gold('gj2h##hg7ur#zt#zhg#e#5h##jgs#kjl')
'gjh##hgur#zt#zhg#e#h##jgs#kjl'

>>> trade('gj1h##hg3ur#zt#zhg#e#2h##jgs#kjl')
'gj1hhg3urztzhge2hjgskjl'
>>> trade('gj2h##hg7ur#zt#zhg#e#5h##jgs#kjl')
'gjh##hgur#zt#zhg#e#h##jgs#kjl'

Epilogue

silent trade
Silent trade (storyboard by midna).