go-by-test/roman/roman.go
2024-09-22 21:07:05 +02:00

29 lines
486 B
Go

package roman
import "strings"
func ConvertToRoman(arabic int) string {
var converted strings.Builder
for arabic > 0 {
switch {
case arabic > 9:
converted.WriteString("X")
arabic -= 10
case arabic > 8:
converted.WriteString("IX")
arabic -= 9
case arabic > 4:
converted.WriteString("V")
arabic -= 5
case arabic > 3:
converted.WriteString("IV")
arabic -= 4
default:
converted.WriteString("I")
arabic -= 1
}
}
return converted.String()
}