SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
Roman Numeral Conversion
Anybody know of a little utility to convert Roman numerals to Arabic numerals; type in the Roman, get the Arabic?
Checking around there's a nice looking (but will not compile) library at SourceForge, couple of Windowish things, none of which compile or run without a lot of twiddling and fiddling.
A little click-'n'-drool thing would be the berries (bunch of Windows folk that don't like command line too much) and I'm just not too capable with Java or some such. Heck, ncurses would be good enough.
The conversion is trivial, but the simple-to-use part without opening a terminal window ain't.
What's funny about your question is that word algorithm is derived from that of Persian mathematician عَبْدَالله مُحَمَّد بِن مُوسَى اَلْخْوَارِزْمِي (in English Al-Khawarizmi), who introduced in Middle East then in Europe the so-called arabic numerals.
Also, word algebra is taken from part of the Arabic title of his best known book.
PS Now I'm sure NSA is watching me
Last edited by Didier Spaier; 10-28-2013 at 10:54 AM.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Original Poster
Rep:
Quote:
Originally Posted by Didier Spaier
What's funny about you question is that word algorithm is derived from that of Persian mathematician عَبْدَالله مُحَمَّد بِن مُوسَى اَلْخْوَارِزْمِي (in English Al-Khawarizmi), who introduced in Middle East then in Europe the so-called arabic numerals.
Also, word algebra is taken from part of the Arabic title of his best known book.
PS Now I'm sure NSA is watching me
You know, I'm not all that sure that NSA gives a hoot about any of us. Just a bunch of weird computer crazies and all that.
Oh, you need something to go along with this to do Arabic to Roman conversion? Here's a handy little program for that:
Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. roman.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 ARRAY.
02 A PIC 9(4) OCCURS 7 TIMES.
02 B PIC X OCCURS 7 TIMES.
77 N PIC 9(4).
77 I PIC 9(2).
77 J PIC 9(2).
77 Q PIC 9(3).
77 R PIC 9(3) VALUE 1.
PROCEDURE DIVISION.
MAIN-PARA.
MOVE 1000 TO A(1).
MOVE 500 TO A(2).
MOVE 100 TO A(3).
MOVE 50 TO A(4).
MOVE 10 TO A(5).
MOVE 5 TO A(6).
MOVE 1 TO A(7).
MOVE "M" TO B(1).
MOVE "D" TO B(2).
MOVE "C" TO B(3).
MOVE "L" TO B(4).
MOVE "X" TO B(5).
MOVE "V" TO B(6).
MOVE "I" TO B(7).
DISPLAY "ENTER ANY NUMBER: " WITH NO ADVANCING.
ACCEPT N.
IF (N = 0)
DISPLAY "ZERO SHOULD NOT BE ENTERED"
STOP RUN.
DISPLAY "THE CORRESPONDING ROMAN NUMBER IS " WITH NO ADVANCING.
PERFORM X-PARA VARYING I FROM 1 BY 1 UNTIL R = 0.
DISPLAY " ".
STOP RUN.
X-PARA.
DIVIDE N BY A(I) GIVING Q REMAINDER R.
MOVE R TO N.
PERFORM Y-PARA VARYING J FROM 1 BY 1 UNTIL J > Q.
Y-PARA.
DISPLAY B(I) WITH NO ADVANCING.
Save it as roman.cob and compile it with: cobc -x roman.cob
As an aside, after I posted this I thought "Gee, that should really display NUMERAL, not NUMBER"... so I edited the post. Then I got a nagging feeling that I'd better compile the edited program just in case, and sure enough it no longer compiled. It output "roman.cob:34 Error, syntax error, unexpected NO, expecting "NO ADVANCING"".
By default, COBOL uses fixed format. This is based on punch card columns. Although I'd kept everything within 80 columns, for some unknown reason columns 73 - 80 are ignored by the compiler. This can be worked around by passing -free to the compiler, which lifts all the column restrictions (and I'd be surprised if this wasn't done for all COBOL that's developed these days... but I guess you never know).
I'm remembering why I hate COBOL. Sorry I brought it up.
By default, COBOL uses fixed format. This is based on punch card columns. Although I'd kept everything within 80 columns, for some unknown reason columns 73 - 80 are ignored by the compiler.
When I was in school, those columns were used for sequence numbering of the cards. If you happened to drop your stack of cards then you could run them through a sorting machine that would arrange them based on the numbers in those columns. The keypunch would automatically add the sequence numbers as you created your code, or you could generate new sequence numbers when you made a copy of your card deck.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Original Poster
Rep:
Quote:
Originally Posted by volkerdi
Oh, you need something to go along with this to do Arabic to Roman conversion? Here's a handy little program for that:
Wow. COBOL. Who knew.
Turns out http://www.novaroma.org/via_romana/numbers.html... um, goes both ways -- type in 1854 you get MDCCCLIV, type in MDCCCLIV you get 1854 (or, for that matter, type in mdcccliv and you get 1854). Exactly what's needed. And exactly what click-'n'-drool users like (Terminal window! We don't need no stinkin' terminal window! -- with due apologies to The Treasure of Sierra Madre).
I remember writing a fair rounding function, in BASIC, sometime in the mid 70's on a Honeywell mainframe (GECOS and all that). An actual BASIC compiler, not an interpreter, and it actually worked (which surprised the heck of me) Then had to turn around and write the same thing in FORTRAN IV (see, Roman numerals!). Thankfully, C has that built-in. Whatsit, the American Society of Testing and Materials Engineers, the ASTM method, if the digit next beyond the digit to be retained... lordy.
Thanks for the blast from the past, appreciate it -- didn't try it (yet) but appreciate it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.