## Mangarevan Counting

### June 20, 2017

Six hundred years ago, the people of the French Polynesian island of Mangareva developed a mixed-radix counting system that combined binary and decimal elements to count from 1 to 799. They had no zero. The digits 1 through 9 had their normal decimal value. Digits K, P, T and V had values 10, 20, 40 and 80, respectively, so they increased in a binary progression. A number *N* was represented as *N* = *n*V + T + P + K + *m*, where *n* and *m* were digits; note that T, P and K did not have modifiers. Thus, 73 is represented as TPK3, 219 is represented as 2VTK9, and 799 is represented as 9VTPK9 in Mangarevan. You might enjoy this article in *Nature* and this article in the *Proceedings of the National Academy of Sciences*. Arithmetic is interesting: 1VPK9 + 1 = 1VT, and 3VPK3 + 2VTK9 = 6VK2.

Your task is to write programs that translate to and from Mangarevan counting numbers. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

In Python, abusing the eval() function.

(@Praxis, your parsing function does not look right. I see it missing newlines and cut short.)

@Jussi: Fixed. Thanks. WordPress recently updated its editor, again, and every time they do something breaks.

In Python with checks on input.

From Mangarevan.c:To Mangarevan.c:The programs are known to run on an Apple Power Mac G4 (AGP Graphics) (450MHz processor, 1GB memory) on both Mac OS 9.2.2 (International English) (the programs interpreted using Leonardo IDE 3.4.1) and Mac OS X 10.4.11 (the programs compiled using Xcode 2.2.1).

(I’ve just completed a gig at London South Bank University and so I’m again just trying to solve the problems posed by this ‘site whilst I try to get a job; I’m well-aware that my solutions are far from the best – but, in my defence, I don’t have any traditional qualifications in computer science :/ )