# tags: roman, numbers, awk, code
#
# Arabic to Roman Number Conversion
# Michael Sanders 2023
# https://busybox.neocities.org/notes/arabic-to-roman.txt
#
# example usage: echo 6 | awk -f arabic-to-roman.txt
#
# note: using standard Roman numerals, the largest number
# that can be represented is 3,999, written as MMMCMXCIX
function toRoman(n) {
if (n !~ /^[0-9]+$/ || n < 1 || n > 3999) return "invalid input"
split("I IV V IX X XL L XC C CD D CM M", roman)
split("1 4 5 9 10 40 50 90 100 400 500 900 1000", arabic)
# loop through array in reverse order building romanNum
for (x = 13; x >= 1; x--) {
while (n >= arabic[x]) {
romanNum = romanNum roman[x]
n -= arabic[x]
}
}
return romanNum
}
{ print toRoman($1) }
# eof
Some years ago I wrote an tool 'aroma' (and I think I also posted
a version here) for arabic <-> roman (bidirectional) conversion.
Here is the version I still have in my local bin directory...
Have fun!
Janis
# aroma - yet another arabic number / roman number converter
[...]
Related with a fun factor:
Stand-up Maths
How Roman numerals broke the official dog database. https://www.youtube.com/watch?v=jMxoGqsmk5Y
Related with a fun factor:
Stand-up Maths
How Roman numerals broke the official dog database. https://www.youtube.com/watch?v=jMxoGqsmk5Y
When using computers there's no reason to stop after 3999,
I'd say.
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
When using computers there's no reason to stop after 3999,
I'd say.
They just would have had a y4k problem and would find a fix for that.
[...]
But only having 3999 addresses would have been even worse than coding on
an 8086 (64k pages) or even a SC/MP (4k pages).
[...]
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 920 |
Nodes: | 10 (0 / 10) |
Uptime: | 100:55:17 |
Calls: | 12,189 |
Calls today: | 1 |
Files: | 186,527 |
Messages: | 2,237,441 |