Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Just think, with VLSI we can have 100 ENIACS on a chip!" -- Alan Perlis


devel / comp.lang.awk / Arabic to Roman Number Conversion

SubjectAuthor
* Arabic to Roman Number ConversionMike Sanders
+* Re: Arabic to Roman Number ConversionJanis Papanagnou
|`- Re: Arabic to Roman Number ConversionMike Sanders
`* Re: Arabic to Roman Number Conversionyeti
 +- Re: Arabic to Roman Number ConversionMike Sanders
 `* Re: Arabic to Roman Number ConversionJanis Papanagnou
  `* Re: Arabic to Roman Number Conversionyeti
   `- Re: Arabic to Roman Number ConversionJanis Papanagnou

1
Arabic to Roman Number Conversion

<uhhk7j$2hffo$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1643&group=comp.lang.awk#1643

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkchop@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.awk
Subject: Arabic to Roman Number Conversion
Date: Sat, 28 Oct 2023 00:22:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <uhhk7j$2hffo$1@dont-email.me>
Injection-Date: Sat, 28 Oct 2023 00:22:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f8a74691c75e6854dec8dcc050a316ff";
logging-data="2670072"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18F6JeQAvAuTFR1BK35qpjA"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:GFaMKwkrGvPdg5nT1bNz8j47iT8=
 by: Mike Sanders - Sat, 28 Oct 2023 00:22 UTC

# 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

--
:wq
Mike Sanders

Re: Arabic to Roman Number Conversion

<uhhtgq$2msmp$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1644&group=comp.lang.awk#1644

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Arabic to Roman Number Conversion
Date: Sat, 28 Oct 2023 05:00:41 +0200
Organization: A noiseless patient Spider
Lines: 97
Message-ID: <uhhtgq$2msmp$1@dont-email.me>
References: <uhhk7j$2hffo$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 28 Oct 2023 03:00:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="078535d56e9195d577a6261a8e470622";
logging-data="2847449"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rmtGi0Klk4X36X66nW2sX"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:P2swe5OQo2d0EkLwHpDTqlEHxTk=
In-Reply-To: <uhhk7j$2hffo$1@dont-email.me>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sat, 28 Oct 2023 03:00 UTC

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
# # Historically, a couple variants of roman numbers have been
# around, a couple alphabets were in use in different regions
# and times and various rules to build and interpret roman
# numbers were existing. In this code we restrict to the basic
# alphabet I, V, X, L, C, D, M and allow simple subtractive
# abbreviations IV, IX, XL, XC, CD, CM; this is often called
# the normal form of the roman numbers. (Deviations from that
# form, e.g. numbers like 'IM' or 'IIX', are not supported.)
# # Janis Papanagnou, 2010

awk -v n="${1?Please provide a number (arabic or roman) as argument!}" '
BEGIN {
split ("1000 900 500 400 100 90 50 40 10 9 5 4 1", ar)
split ("M CM D CD C XC L XL X IX V IV I", ro)
if (n ~ /^[[:digit:]]+$/) {
print ar2ro(n) # output in unique normal form
} else if (n ~ /^[MDCLXVI]*$/) {
x = ro2ar(n) # a consistency test follows
print (ar2ro(x) == n) ? x : "NaN"
} else {
print "NaN"
}
}

function ro2ar (r, a, i)
{
a = 0
for (i=1; r && ro[i]; i++)
{
l = length (ro[i])
while (substr (r,1,l) == ro[i]) {
a += ar[i]
r = substr (r,l+1)
}
}
return (r == "") ? a : "NaN"
}

function ar2ro (a, r, i)
{
for (i=1; ar[i]; i++) {
while (a >= ar[i]) {
a -= ar[i]
r = r ro[i]
}
}
return r
}
'

# vim: ts=4 sw=4 syntax=awk

On 28.10.2023 02:22, Mike Sanders wrote:
> # 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
>

Re: Arabic to Roman Number Conversion

<uhhvp9$2n56r$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1645&group=comp.lang.awk#1645

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkchop@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.awk
Subject: Re: Arabic to Roman Number Conversion
Date: Sat, 28 Oct 2023 03:39:21 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 22
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <uhhvp9$2n56r$1@dont-email.me>
References: <uhhk7j$2hffo$1@dont-email.me> <uhhtgq$2msmp$1@dont-email.me>
Injection-Date: Sat, 28 Oct 2023 03:39:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f8a74691c75e6854dec8dcc050a316ff";
logging-data="2856155"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9JDjmDwY2xmlT3TuN0H8L"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:8uH1fr9ZBtJumEv85R8U4mo83SY=
 by: Mike Sanders - Sat, 28 Oct 2023 03:39 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> 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
>
> [...]

This is really nice Janis & conversion both ways too, cool =)
Thanks for sharing this, have added yours to my personal notes.

Here, I lowercase output, good for footnotes: ('see also [iii]')

--
:wq
Mike Sanders

Re: Arabic to Roman Number Conversion

<877cn7ibe5.fsf@tilde.institute>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1646&group=comp.lang.awk#1646

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: yeti@tilde.institute (yeti)
Newsgroups: comp.lang.awk
Subject: Re: Arabic to Roman Number Conversion
Date: Sat, 28 Oct 2023 05:06:26 +0000
Organization: Democratic Order of Pirates International (DOPI)
Lines: 8
Message-ID: <877cn7ibe5.fsf@tilde.institute>
References: <uhhk7j$2hffo$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="bb71ce2cd5c9299ea04c2ae2537cdd53";
logging-data="2882080"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RImS+THjAWw58YR0WSPTi"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:LygafiGICz4lgqVwK6iku857/GY=
sha1:BmJ1GbfOfc+chCsNeQwM63iXoXQ=
X-Face: ]_G&_b@O$RF(L7zT;DQ3-VU}c"F/_Mgy(4^P1,Tt^#0Cq+\qM&-h\&Z.3UuiwV")n~b;26e
5-s.cF/5tMdha-:]4eBHC9vBXnz4_aNe@d4oijVyix?>pC=tzuQhoD2A8P02+\xO4gNfRBE
`B<kE3T-Gps_d0_6`+0W3E9{D
 by: yeti - Sat, 28 Oct 2023 05:06 UTC

Related with a fun factor:

Stand-up Maths
How Roman numerals broke the official dog database.
https://www.youtube.com/watch?v=jMxoGqsmk5Y

--
Fake signature.

Re: Arabic to Roman Number Conversion

<uhimas$2qtl6$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1647&group=comp.lang.awk#1647

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkchop@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.awk
Subject: Re: Arabic to Roman Number Conversion
Date: Sat, 28 Oct 2023 10:04:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <uhimas$2qtl6$1@dont-email.me>
References: <uhhk7j$2hffo$1@dont-email.me> <877cn7ibe5.fsf@tilde.institute>
Injection-Date: Sat, 28 Oct 2023 10:04:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f8a74691c75e6854dec8dcc050a316ff";
logging-data="2979494"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4/2N4/xYdhIiGbqA6pntM"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:+lMieZ050h4yx23ROwOeD1ao/zE=
 by: Mike Sanders - Sat, 28 Oct 2023 10:04 UTC

yeti <yeti@tilde.institute> wrote:

> Related with a fun factor:
>
> Stand-up Maths
> How Roman numerals broke the official dog database.
> https://www.youtube.com/watch?v=jMxoGqsmk5Y

Ahh... nice. Sometimes youtube is really good =)

--
:wq
Mike Sanders

Re: Arabic to Roman Number Conversion

<uhj10n$2ssmt$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1649&group=comp.lang.awk#1649

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Arabic to Roman Number Conversion
Date: Sat, 28 Oct 2023 15:06:30 +0200
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <uhj10n$2ssmt$1@dont-email.me>
References: <uhhk7j$2hffo$1@dont-email.me> <877cn7ibe5.fsf@tilde.institute>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 28 Oct 2023 13:06:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="73d1a1247b0411d13184f88071ecf0f3";
logging-data="3044061"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MP/QbvZ86OtQ26S0mQuPz"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:yEbVV+BEqgml7dWrJ4HtBAQ14gk=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <877cn7ibe5.fsf@tilde.institute>
 by: Janis Papanagnou - Sat, 28 Oct 2023 13:06 UTC

On 28.10.2023 07:06, yeti wrote:
> Related with a fun factor:
>
> Stand-up Maths
> How Roman numerals broke the official dog database.
> https://www.youtube.com/watch?v=jMxoGqsmk5Y

Nice!

This video mentions - as Mike's code did[*] - the number
3999 as maximum roman number; *one* link I found mentions
a "not more than three same digits _principle_". Actually
I could not find any such principle. From early days I've
learned that a sequence of MMMMMMMM is just too bulky in
practice but not that it would be incorrect. Wikipedias
mention that there were many ways to face that bulkiness
with new notations. And also that sequences of four digits
were and still are quite usual. The English Wikipedia has
a table that stops at MMM, but I'm not sure whether just
for convenience or because of some general "principle"[**].

When using computers there's no reason to stop after 3999,
I'd say.

Janis

[*] ... || n < 1 || n > 3999) return "invalid input"

[**] Any (authoritative) links appreciated.

Re: Arabic to Roman Number Conversion

<87ttqagsfv.fsf@tilde.institute>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1650&group=comp.lang.awk#1650

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: yeti@tilde.institute (yeti)
Newsgroups: comp.lang.awk
Subject: Re: Arabic to Roman Number Conversion
Date: Sun, 29 Oct 2023 00:53:24 +0000
Organization: Democratic Order of Pirates International (DOPI)
Lines: 36
Message-ID: <87ttqagsfv.fsf@tilde.institute>
References: <uhhk7j$2hffo$1@dont-email.me> <877cn7ibe5.fsf@tilde.institute>
<uhj10n$2ssmt$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="4f61e20c8678611bc23c8d954fd886dd";
logging-data="3739158"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CxM1Ft4eQrUULUUtVBvFC"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:METIzr+LkimcuR7qgMd7l2qsEOQ=
sha1:Zn7yXbHtenFHWRIkoiyS6X1EftU=
X-Face: ]_G&_b@O$RF(L7zT;DQ3-VU}c"F/_Mgy(4^P1,Tt^#0Cq+\qM&-h\&Z.3UuiwV")n~b;26e
5-s.cF/5tMdha-:]4eBHC9vBXnz4_aNe@d4oijVyix?>pC=tzuQhoD2A8P02+\xO4gNfRBE
`B<kE3T-Gps_d0_6`+0W3E9{D
 by: yeti - Sun, 29 Oct 2023 00:53 UTC

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).

Maybe Cisterian numerals would have helped to push that to y10k?

<https://en.wikipedia.org/wiki/Cistercian_numerals>

But with increasing use of math(s) and science they would have needed an
easier number system. Even far below the finite count of subatomic
particles in the universe, combinations and similar concepts make counts
explode.

And calculations in Roman numerals must have been hell. Are there known
algorithms?

And the missing zero!

That was a number system for the "you are what you have" era.

A shepherd is someone with sheep.

No sheep? => Not a shepherd!
:-Þ

--
|rom The Future. +++ Breaking News From The Future. +++ Breaking News F|
| The USoA are switching to the binary number system because |
| having more than 1+1 distinct digits is far too woke. |
|+ #MABA + #makeAmericaBinaryAgain + #USA + #USoA + #woke + #MABA + #ma|

Re: Arabic to Roman Number Conversion

<uhlju6$3sghb$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1652&group=comp.lang.awk#1652

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Arabic to Roman Number Conversion
Date: Sun, 29 Oct 2023 13:41:41 +0100
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <uhlju6$3sghb$1@dont-email.me>
References: <uhhk7j$2hffo$1@dont-email.me> <877cn7ibe5.fsf@tilde.institute>
<uhj10n$2ssmt$1@dont-email.me> <87ttqagsfv.fsf@tilde.institute>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 29 Oct 2023 12:41:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bc2f41efda93874e74777b75f27d4e87";
logging-data="4080171"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KLFOUtof9IeDHQ02u7Iij"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:7VS1Ds1E89Xp9FdvGzJIsxj8UCA=
In-Reply-To: <87ttqagsfv.fsf@tilde.institute>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sun, 29 Oct 2023 12:41 UTC

On 29.10.2023 02:53, yeti wrote:
> 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).
> [...]

Sure. - My question was whether it makes sense to hard-code such a
constant in a computer program (that is only run digitally) in the
first place.[*] If someone wants to see a date, say 6543, in roman
and he just gets "invalid input" is worse than "MMMMMMDXLIII", IMO.

One [valid] reason for an error message might be if it's strictly
"undefined" (by some relevant instance) when values grow larger;
but I haven't found any. Even the web page I found that speaks of
such a "not-four-consecutive-digits rule" starts with a photo that
depicts a tower clock with 'IIII'; and this is obviously a common
representation (from ancient usages till now) in roman numerals.

Moreover, if you inspect the historic and scientific documents you
observe that there had been also _so many_ of variants[**] that it
appears strange in that light to think of such a rule.[***]

That's why I was asking for a relevant reference for such a rule or
principle.

Janis

[*] We nowadays also calculate Pi to ludicrous accuracies (and "no
one" is attempting to print these digits on paper).

[**] Even the humorously intended "subtracting two" that we see in
the video that was posted upthread is one of the existing historic
variants.

[***] In practice folks use (inferior) [number-]systems as they fit
and extend them when necessary. I would expect that they first try
to stretch the existing system, then to enhance it by inventing new
digits. (As has been done for large roman numerals.) Dropping that
inferior (for reasons as you've described) system completely usually
is a disruptive process that requires more wisdom and persistence to
implement in society broadly.[****]

[****] E.g., see climate crisis and traffic congestion in cities and
(OTOH) abandonment of cars, for example. - But I am digressing.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor