2020-03-12 15:43:05 +00:00
## romannumbers
### Instructions
2020-03-12 19:11:32 +00:00
Write a program called `rn` . The objective is to convert a number, given as an argument, into a roman number and print it with its roman number calculation.
2020-03-12 15:43:05 +00:00
2021-06-23 03:07:57 +00:00
The program should have a limit of `4000` . In case of an invalid number, for example `"hello"` or `0` the program should print `ERROR: cannot convert to roman digit` .
2020-03-12 19:11:32 +00:00
Roman Numerals reminder:
2020-03-12 19:15:49 +00:00
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
2020-04-26 10:29:55 +00:00
| I | 1 |
| :-: | :--: |
| V | 5 |
| X | 10 |
| L | 50 |
| C | 100 |
| D | 500 |
| M | 1000 |
2020-03-12 19:15:49 +00:00
2020-03-12 19:11:32 +00:00
For example, the number 1732 would be denoted MDCCXXXII in Roman numerals. However, Roman numerals are not a purely additive number system. In particular, instead of using four symbols to represent a 4, 40, 9, 90, etc. (i.e., IIII, XXXX, VIIII, LXXXX, etc.), such numbers are instead denoted by preceding the symbol for 5, 50, 10, 100, etc., with a symbol indicating subtraction. For example, 4 is denoted IV, 9 as IX, 40 as XL, etc.
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
2020-04-26 10:29:55 +00:00
The following table gives the Roman numerals for the first few positive integers.
| 1 | I | 11 | XI | 21 | XXI |
| :-: | :--: | :-: | :---: | :-: | :----: |
| 2 | II | 12 | XII | 22 | XXII |
| 3 | III | 13 | XIII | 23 | XXIII |
| 4 | IV | 14 | XIV | 24 | XXIV |
| 5 | V | 15 | XV | 25 | XXV |
| 6 | VI | 16 | XVI | 26 | XXVI |
| 7 | VII | 17 | XVII | 27 | XXVII |
| 8 | VIII | 18 | XVIII | 28 | XXVIII |
2022-11-17 10:15:57 +00:00
| 9 | IX | 19 | XIX | 29 | XXIX |
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
2020-04-26 10:29:55 +00:00
| 10 | X | 20 | XX | 30 | XXX |
2020-03-12 15:43:05 +00:00
## Usage
```console
2021-04-28 09:47:34 +00:00
$ go run . hello
2021-06-23 03:07:57 +00:00
ERROR: cannot convert to roman digit
2021-04-28 09:47:34 +00:00
$ go run . 123
2020-03-12 15:43:05 +00:00
C+X+X+I+I+I
CXXIII
2021-04-28 09:47:34 +00:00
$ go run . 999
2020-03-12 15:43:05 +00:00
(M-C)+(C-X)+(X-I)
CMXCIX
2021-04-28 09:47:34 +00:00
$ go run . 3999
2020-03-12 15:43:05 +00:00
M+M+M+(M-C)+(C-X)+(X-I)
MMMCMXCIX
2021-04-28 09:47:34 +00:00
$ go run . 4000
2021-06-23 03:07:57 +00:00
ERROR: cannot convert to roman digit
2021-04-28 09:47:34 +00:00
$
2020-03-12 15:43:05 +00:00
```