Coding Dojo: Converting between different numeral systems
Converting numeral systems
During this session we will explore converting between different numeral systems. The numeral system we commonly use in the West (1,2,3 etc) is called Western Arabic. Although it's actually Hindu (Arabic traders brought it to Europe via India), we will refer to it as Arabic. In central Europe this eventually replaced a simplistic system called Urnfield.
Specification
We require a program that will convert between 3 different numeral systems; Arabic, Roman, Urnfield.
The following ranges are required:
- Roman: 1..3499
- Urnfield: 1..29
Roman
Roman numerals are based on seven symbols which can be combined to represent numbers.
Roman Symbol | Arabic Value |
---|---|
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 1000 |
Generally, Roman numerals are written in descending order from left to right, and are added sequentially, for example MMVI (2006) is interpreted as 1000 + 1000 + 5 + 1.
Urnfield
Urnfield is a simplistic numeral system used around 1200 BC in central Europe. It uses only 2 characters which are both slashes.
Urnfield Symbol | Arabic Value |
---|---|
/ | 1 |
\ | 5 |
Each forward slash represents 1 and appears first, there is at most 4. After that downward slashes each represent 5. For example //\\\ (17) is interpreted as 1 + 1 + 5 + 5 + 5.