2024-09-22 18:53:13 +00:00
|
|
|
package roman
|
|
|
|
|
2024-09-22 18:54:22 +00:00
|
|
|
import "strings"
|
|
|
|
|
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: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:
|
2024-09-22 18:59:11 +00:00
|
|
|
converted.WriteString("IV")
|
2024-09-22 19:02:27 +00:00
|
|
|
arabic -= 4
|
|
|
|
default:
|
|
|
|
converted.WriteString("I")
|
|
|
|
arabic -= 1
|
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
|
|
|
}
|