go-by-test/roman/roman.go

29 lines
486 B
Go
Raw Normal View History

package roman
import "strings"
func ConvertToRoman(arabic int) string {
var converted strings.Builder
2024-09-22 19:02:27 +00:00
for arabic > 0 {
switch {
2024-09-22 19:07:05 +00:00
case arabic > 9:
converted.WriteString("X")
arabic -= 10
case arabic > 8:
converted.WriteString("IX")
arabic -= 9
2024-09-22 19:02:27 +00:00
case arabic > 4:
converted.WriteString("V")
arabic -= 5
case arabic > 3:
converted.WriteString("IV")
2024-09-22 19:02:27 +00:00
arabic -= 4
default:
converted.WriteString("I")
arabic -= 1
}
2024-09-22 18:57:12 +00:00
}
2024-09-22 19:02:27 +00:00
return converted.String()
}