https://github.com/nikoheikkila/roman-numeral-encoder
Kata: Roman Numerals Encoder
https://github.com/nikoheikkila/roman-numeral-encoder
algorithm go golang kata
Last synced: 7 days ago
JSON representation
Kata: Roman Numerals Encoder
- Host: GitHub
- URL: https://github.com/nikoheikkila/roman-numeral-encoder
- Owner: nikoheikkila
- Created: 2020-03-11T20:31:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-12T06:18:59.000Z (over 6 years ago)
- Last Synced: 2025-04-03T03:33:11.020Z (about 1 year ago)
- Topics: algorithm, go, golang, kata
- Language: Go
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Roman Numeral Encoder
This is a programming Kata taken from [Codewars](https://www.codewars.com/kata/51b62bf6a9c58071c600001b) and implemented in _Golang_.
## Solution
Split an integer to its sum factors. Then convert each factor to a roman numeral. Finally, concatenate numerals to get the result.
**Example 1: `2020` to Roman:**
```go
n := 2020
= 2000 + 20
= 1000 + 1000 + 20
= 1000 + 1000 + 10 + 10
= {M} + 1000 + 10 + 10
= {M} + {M} + 10 + 10
= {M} + {M} + {X} + 10
= {M, M} + {X, X}
= MM + XX
= MMXX
```
**Example 1: `8192` to Roman:**
Following example skips some of the trivial steps for brevity's sake.
```go
n := 8192
= 8000 + 100 + 90 + 2
= {M, M, M, M} + 100 + 90 + 2
= {M, M, M, M} + {C} + 90 + 2
= {M, M, M, M} + {C} + {XC} + 2
= {M, M, M, M} + {C} + {XC} + {II}
= MMMM + C + XC + II
= MMMMMMMMCXCII
```
See [here](encoder/encoder.go) for my complete solution.
## Testing
Use `./test.sh` to run both unit tests and performance benchmarks.