mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-10-29 22:17:23 +01:00
feat(challenges): add roman-numerals
This commit is contained in:
parent
57950426d3
commit
213ae08fb3
45
challenges/roman-numerals/README.md
Normal file
45
challenges/roman-numerals/README.md
Normal file
@ -0,0 +1,45 @@
|
||||
# roman-numerals
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 30 June 2021.
|
||||
|
||||
## Instructions
|
||||
|
||||
The objective of this challenge is to create a function that translates a number into Roman numerals or the other way around.
|
||||
|
||||
We will use the letters `I`, `V`, `X`, `L`, `C`, `D`, `M` to build the Roman numerals.
|
||||
|
||||
Here are the rules for building a Roman numeral:
|
||||
|
||||
- The numbers `1`, `2` and `3` are written respectively as `I`, `II` and `III`
|
||||
- The number `5` is written as `V`
|
||||
- The number `10` is written as `X`
|
||||
- The number `50` is written as `L`
|
||||
- The number `100` is written as `C`
|
||||
- The number `500` is written as `D`
|
||||
- The number `1000` is written as `M`
|
||||
- When writing two letters in a row, if the numerical value of the first is greater than the numerical value of the second, their numerical values are added. For example the number `6` is written `VI`. We add `V` (5) + `I` (1) = 6.
|
||||
- When writing two letters in a row, if the numerical value of the first is less than the numerical value of the second, the value of the first is subtracted from the second. For example the number `4` is written `IV`. We subtract `V` (5) - `I` (1) = 4.
|
||||
- Subtractions of values are limited to 2 letters only. For example we **cannot** write `8` while doing `IIX`. We must use the addition of letters like this `VIII`.
|
||||
- Therefore, the first ten numbers are written as `I`, `II`, `III`, `IV`, `V`, `VI`, `VII`, `VIII`, `IX`, `X` . Larger numbers follow the same pattern.
|
||||
- You can associate as many symbols as you want to write larger numbers, for example:
|
||||
- `36` is written as `XXXVI`
|
||||
- `42` is written as `XLII`
|
||||
- `2448` is written as `MMCDXLVIII`.
|
||||
|
||||
| Symbol | I | V | X | L | C | D | M |
|
||||
|--------|---|---|----|----|-----|-----|------|
|
||||
| Value | 1 | 5 | 10 | 50 | 100 | 500 | 1000 |
|
||||
|
||||
### Input
|
||||
|
||||
- **Line 1:** The string : `arabic to roman` or `roman to arabic` to determine how to convert the number
|
||||
- **Line 2:** The number to convert
|
||||
|
||||
## Source
|
||||
|
||||
- [Wikipedia - Roman numerals](https://en.wikipedia.org/wiki/Roman_numerals)
|
||||
- [Wikipedia - Arabic numerals](https://en.wikipedia.org/wiki/Arabic_numerals)
|
||||
|
||||
## Examples
|
||||
|
||||
See the `test` folder for examples of input/output.
|
0
challenges/roman-numerals/solutions/.gitkeep
Normal file
0
challenges/roman-numerals/solutions/.gitkeep
Normal file
2
challenges/roman-numerals/test/1/input.txt
Normal file
2
challenges/roman-numerals/test/1/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
1
|
1
challenges/roman-numerals/test/1/output.txt
Normal file
1
challenges/roman-numerals/test/1/output.txt
Normal file
@ -0,0 +1 @@
|
||||
I
|
2
challenges/roman-numerals/test/10/input.txt
Normal file
2
challenges/roman-numerals/test/10/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
59
|
1
challenges/roman-numerals/test/10/output.txt
Normal file
1
challenges/roman-numerals/test/10/output.txt
Normal file
@ -0,0 +1 @@
|
||||
LIX
|
2
challenges/roman-numerals/test/11/input.txt
Normal file
2
challenges/roman-numerals/test/11/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
93
|
1
challenges/roman-numerals/test/11/output.txt
Normal file
1
challenges/roman-numerals/test/11/output.txt
Normal file
@ -0,0 +1 @@
|
||||
XCIII
|
2
challenges/roman-numerals/test/12/input.txt
Normal file
2
challenges/roman-numerals/test/12/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
99
|
1
challenges/roman-numerals/test/12/output.txt
Normal file
1
challenges/roman-numerals/test/12/output.txt
Normal file
@ -0,0 +1 @@
|
||||
XCIX
|
2
challenges/roman-numerals/test/13/input.txt
Normal file
2
challenges/roman-numerals/test/13/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
141
|
1
challenges/roman-numerals/test/13/output.txt
Normal file
1
challenges/roman-numerals/test/13/output.txt
Normal file
@ -0,0 +1 @@
|
||||
CXLI
|
2
challenges/roman-numerals/test/14/input.txt
Normal file
2
challenges/roman-numerals/test/14/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
163
|
1
challenges/roman-numerals/test/14/output.txt
Normal file
1
challenges/roman-numerals/test/14/output.txt
Normal file
@ -0,0 +1 @@
|
||||
CLXIII
|
2
challenges/roman-numerals/test/15/input.txt
Normal file
2
challenges/roman-numerals/test/15/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
369
|
1
challenges/roman-numerals/test/15/output.txt
Normal file
1
challenges/roman-numerals/test/15/output.txt
Normal file
@ -0,0 +1 @@
|
||||
CCCLXIX
|
2
challenges/roman-numerals/test/16/input.txt
Normal file
2
challenges/roman-numerals/test/16/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
402
|
1
challenges/roman-numerals/test/16/output.txt
Normal file
1
challenges/roman-numerals/test/16/output.txt
Normal file
@ -0,0 +1 @@
|
||||
CDII
|
2
challenges/roman-numerals/test/17/input.txt
Normal file
2
challenges/roman-numerals/test/17/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
575
|
1
challenges/roman-numerals/test/17/output.txt
Normal file
1
challenges/roman-numerals/test/17/output.txt
Normal file
@ -0,0 +1 @@
|
||||
DLXXV
|
2
challenges/roman-numerals/test/18/input.txt
Normal file
2
challenges/roman-numerals/test/18/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
911
|
1
challenges/roman-numerals/test/18/output.txt
Normal file
1
challenges/roman-numerals/test/18/output.txt
Normal file
@ -0,0 +1 @@
|
||||
CMXI
|
2
challenges/roman-numerals/test/19/input.txt
Normal file
2
challenges/roman-numerals/test/19/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
999
|
1
challenges/roman-numerals/test/19/output.txt
Normal file
1
challenges/roman-numerals/test/19/output.txt
Normal file
@ -0,0 +1 @@
|
||||
CMXCIX
|
2
challenges/roman-numerals/test/2/input.txt
Normal file
2
challenges/roman-numerals/test/2/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
2
|
1
challenges/roman-numerals/test/2/output.txt
Normal file
1
challenges/roman-numerals/test/2/output.txt
Normal file
@ -0,0 +1 @@
|
||||
II
|
2
challenges/roman-numerals/test/20/input.txt
Normal file
2
challenges/roman-numerals/test/20/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
1024
|
1
challenges/roman-numerals/test/20/output.txt
Normal file
1
challenges/roman-numerals/test/20/output.txt
Normal file
@ -0,0 +1 @@
|
||||
MXXIV
|
2
challenges/roman-numerals/test/21/input.txt
Normal file
2
challenges/roman-numerals/test/21/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
2751
|
1
challenges/roman-numerals/test/21/output.txt
Normal file
1
challenges/roman-numerals/test/21/output.txt
Normal file
@ -0,0 +1 @@
|
||||
MMDCCLI
|
2
challenges/roman-numerals/test/22/input.txt
Normal file
2
challenges/roman-numerals/test/22/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
3000
|
1
challenges/roman-numerals/test/22/output.txt
Normal file
1
challenges/roman-numerals/test/22/output.txt
Normal file
@ -0,0 +1 @@
|
||||
MMM
|
2
challenges/roman-numerals/test/23/input.txt
Normal file
2
challenges/roman-numerals/test/23/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
I
|
1
challenges/roman-numerals/test/23/output.txt
Normal file
1
challenges/roman-numerals/test/23/output.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
2
challenges/roman-numerals/test/24/input.txt
Normal file
2
challenges/roman-numerals/test/24/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
II
|
1
challenges/roman-numerals/test/24/output.txt
Normal file
1
challenges/roman-numerals/test/24/output.txt
Normal file
@ -0,0 +1 @@
|
||||
2
|
2
challenges/roman-numerals/test/25/input.txt
Normal file
2
challenges/roman-numerals/test/25/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
III
|
1
challenges/roman-numerals/test/25/output.txt
Normal file
1
challenges/roman-numerals/test/25/output.txt
Normal file
@ -0,0 +1 @@
|
||||
3
|
2
challenges/roman-numerals/test/26/input.txt
Normal file
2
challenges/roman-numerals/test/26/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
IV
|
1
challenges/roman-numerals/test/26/output.txt
Normal file
1
challenges/roman-numerals/test/26/output.txt
Normal file
@ -0,0 +1 @@
|
||||
4
|
2
challenges/roman-numerals/test/27/input.txt
Normal file
2
challenges/roman-numerals/test/27/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
V
|
1
challenges/roman-numerals/test/27/output.txt
Normal file
1
challenges/roman-numerals/test/27/output.txt
Normal file
@ -0,0 +1 @@
|
||||
5
|
2
challenges/roman-numerals/test/28/input.txt
Normal file
2
challenges/roman-numerals/test/28/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
VI
|
1
challenges/roman-numerals/test/28/output.txt
Normal file
1
challenges/roman-numerals/test/28/output.txt
Normal file
@ -0,0 +1 @@
|
||||
6
|
2
challenges/roman-numerals/test/29/input.txt
Normal file
2
challenges/roman-numerals/test/29/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
IX
|
1
challenges/roman-numerals/test/29/output.txt
Normal file
1
challenges/roman-numerals/test/29/output.txt
Normal file
@ -0,0 +1 @@
|
||||
9
|
2
challenges/roman-numerals/test/3/input.txt
Normal file
2
challenges/roman-numerals/test/3/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
3
|
1
challenges/roman-numerals/test/3/output.txt
Normal file
1
challenges/roman-numerals/test/3/output.txt
Normal file
@ -0,0 +1 @@
|
||||
III
|
2
challenges/roman-numerals/test/30/input.txt
Normal file
2
challenges/roman-numerals/test/30/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
XXVII
|
1
challenges/roman-numerals/test/30/output.txt
Normal file
1
challenges/roman-numerals/test/30/output.txt
Normal file
@ -0,0 +1 @@
|
||||
27
|
2
challenges/roman-numerals/test/31/input.txt
Normal file
2
challenges/roman-numerals/test/31/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
XLVIII
|
1
challenges/roman-numerals/test/31/output.txt
Normal file
1
challenges/roman-numerals/test/31/output.txt
Normal file
@ -0,0 +1 @@
|
||||
48
|
2
challenges/roman-numerals/test/32/input.txt
Normal file
2
challenges/roman-numerals/test/32/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
LIX
|
1
challenges/roman-numerals/test/32/output.txt
Normal file
1
challenges/roman-numerals/test/32/output.txt
Normal file
@ -0,0 +1 @@
|
||||
59
|
2
challenges/roman-numerals/test/33/input.txt
Normal file
2
challenges/roman-numerals/test/33/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
XCIII
|
1
challenges/roman-numerals/test/33/output.txt
Normal file
1
challenges/roman-numerals/test/33/output.txt
Normal file
@ -0,0 +1 @@
|
||||
93
|
2
challenges/roman-numerals/test/34/input.txt
Normal file
2
challenges/roman-numerals/test/34/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
XCIX
|
1
challenges/roman-numerals/test/34/output.txt
Normal file
1
challenges/roman-numerals/test/34/output.txt
Normal file
@ -0,0 +1 @@
|
||||
99
|
2
challenges/roman-numerals/test/35/input.txt
Normal file
2
challenges/roman-numerals/test/35/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
CXLI
|
1
challenges/roman-numerals/test/35/output.txt
Normal file
1
challenges/roman-numerals/test/35/output.txt
Normal file
@ -0,0 +1 @@
|
||||
141
|
2
challenges/roman-numerals/test/36/input.txt
Normal file
2
challenges/roman-numerals/test/36/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
CLXIII
|
1
challenges/roman-numerals/test/36/output.txt
Normal file
1
challenges/roman-numerals/test/36/output.txt
Normal file
@ -0,0 +1 @@
|
||||
163
|
2
challenges/roman-numerals/test/37/input.txt
Normal file
2
challenges/roman-numerals/test/37/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
CCCLXIX
|
1
challenges/roman-numerals/test/37/output.txt
Normal file
1
challenges/roman-numerals/test/37/output.txt
Normal file
@ -0,0 +1 @@
|
||||
369
|
2
challenges/roman-numerals/test/38/input.txt
Normal file
2
challenges/roman-numerals/test/38/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
CDII
|
1
challenges/roman-numerals/test/38/output.txt
Normal file
1
challenges/roman-numerals/test/38/output.txt
Normal file
@ -0,0 +1 @@
|
||||
402
|
2
challenges/roman-numerals/test/39/input.txt
Normal file
2
challenges/roman-numerals/test/39/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
DLXXV
|
1
challenges/roman-numerals/test/39/output.txt
Normal file
1
challenges/roman-numerals/test/39/output.txt
Normal file
@ -0,0 +1 @@
|
||||
575
|
2
challenges/roman-numerals/test/4/input.txt
Normal file
2
challenges/roman-numerals/test/4/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
4
|
1
challenges/roman-numerals/test/4/output.txt
Normal file
1
challenges/roman-numerals/test/4/output.txt
Normal file
@ -0,0 +1 @@
|
||||
IV
|
2
challenges/roman-numerals/test/40/input.txt
Normal file
2
challenges/roman-numerals/test/40/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
CMXI
|
1
challenges/roman-numerals/test/40/output.txt
Normal file
1
challenges/roman-numerals/test/40/output.txt
Normal file
@ -0,0 +1 @@
|
||||
911
|
2
challenges/roman-numerals/test/41/input.txt
Normal file
2
challenges/roman-numerals/test/41/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
CMXCIX
|
1
challenges/roman-numerals/test/41/output.txt
Normal file
1
challenges/roman-numerals/test/41/output.txt
Normal file
@ -0,0 +1 @@
|
||||
999
|
2
challenges/roman-numerals/test/42/input.txt
Normal file
2
challenges/roman-numerals/test/42/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
MXXIV
|
1
challenges/roman-numerals/test/42/output.txt
Normal file
1
challenges/roman-numerals/test/42/output.txt
Normal file
@ -0,0 +1 @@
|
||||
1024
|
2
challenges/roman-numerals/test/43/input.txt
Normal file
2
challenges/roman-numerals/test/43/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
MMDCCLI
|
1
challenges/roman-numerals/test/43/output.txt
Normal file
1
challenges/roman-numerals/test/43/output.txt
Normal file
@ -0,0 +1 @@
|
||||
2751
|
2
challenges/roman-numerals/test/44/input.txt
Normal file
2
challenges/roman-numerals/test/44/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
roman to arabic
|
||||
MMM
|
1
challenges/roman-numerals/test/44/output.txt
Normal file
1
challenges/roman-numerals/test/44/output.txt
Normal file
@ -0,0 +1 @@
|
||||
3000
|
2
challenges/roman-numerals/test/5/input.txt
Normal file
2
challenges/roman-numerals/test/5/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
5
|
1
challenges/roman-numerals/test/5/output.txt
Normal file
1
challenges/roman-numerals/test/5/output.txt
Normal file
@ -0,0 +1 @@
|
||||
V
|
2
challenges/roman-numerals/test/6/input.txt
Normal file
2
challenges/roman-numerals/test/6/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
6
|
1
challenges/roman-numerals/test/6/output.txt
Normal file
1
challenges/roman-numerals/test/6/output.txt
Normal file
@ -0,0 +1 @@
|
||||
VI
|
2
challenges/roman-numerals/test/7/input.txt
Normal file
2
challenges/roman-numerals/test/7/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
9
|
1
challenges/roman-numerals/test/7/output.txt
Normal file
1
challenges/roman-numerals/test/7/output.txt
Normal file
@ -0,0 +1 @@
|
||||
IX
|
2
challenges/roman-numerals/test/8/input.txt
Normal file
2
challenges/roman-numerals/test/8/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
27
|
1
challenges/roman-numerals/test/8/output.txt
Normal file
1
challenges/roman-numerals/test/8/output.txt
Normal file
@ -0,0 +1 @@
|
||||
XXVII
|
2
challenges/roman-numerals/test/9/input.txt
Normal file
2
challenges/roman-numerals/test/9/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
arabic to roman
|
||||
48
|
1
challenges/roman-numerals/test/9/output.txt
Normal file
1
challenges/roman-numerals/test/9/output.txt
Normal file
@ -0,0 +1 @@
|
||||
XLVIII
|
Loading…
Reference in New Issue
Block a user