2024-09-22 18:53:13 +00:00
|
|
|
package roman
|
|
|
|
|
2024-09-22 18:54:22 +00:00
|
|
|
import "strings"
|
|
|
|
|
2024-09-22 19:12:56 +00:00
|
|
|
type RomanNumeral struct {
|
|
|
|
Value int
|
|
|
|
Symbol string
|
|
|
|
}
|
|
|
|
|
|
|
|
var allRomanNumerals = []RomanNumeral{
|
|
|
|
{10, "X"},
|
|
|
|
{9, "IX"},
|
|
|
|
{5, "V"},
|
|
|
|
{4, "IV"},
|
|
|
|
{1, "I"},
|
|
|
|
}
|
|
|
|
|
2024-09-22 18:53:13 +00:00
|
|
|
func ConvertToRoman(arabic int) string {
|
2024-09-22 18:54:22 +00:00
|
|
|
var converted strings.Builder
|
2024-09-22 19:12:56 +00:00
|
|
|
for _, numeral := range allRomanNumerals {
|
|
|
|
for arabic >= numeral.Value {
|
|
|
|
converted.WriteString(numeral.Symbol)
|
|
|
|
arabic -= numeral.Value
|
2024-09-22 18:53:13 +00:00
|
|
|
}
|
2024-09-22 18:57:12 +00:00
|
|
|
}
|
2024-09-22 19:02:27 +00:00
|
|
|
|
2024-09-22 18:54:22 +00:00
|
|
|
return converted.String()
|
2024-09-22 18:53:13 +00:00
|
|
|
}
|