go-by-test/roman/roman.go

42 lines
617 B
Go

package roman
import "strings"
type RomanNumeral struct {
Value int
Symbol string
}
var allRomanNumerals = []RomanNumeral{
{1000, "M"},
{900, "CM"},
{500, "D"},
{400, "CD"},
{900, "CM"},
{100, "C"},
{90, "XC"},
{50, "L"},
{40, "XL"},
{10, "X"},
{9, "IX"},
{5, "V"},
{4, "IV"},
{1, "I"},
}
func ConvertToRoman(arabic int) string {
var converted strings.Builder
for _, numeral := range allRomanNumerals {
for arabic >= numeral.Value {
converted.WriteString(numeral.Symbol)
arabic -= numeral.Value
}
}
return converted.String()
}
func ConvertToArabic(roman string) int {
return 1
}