LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-28-2013, 09:47 AM   #1
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
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.

Can't use a web-based converter (there's a really nice one at http://www.onlineconversion.com/roma...s_advanced.htm but it can't be used at the site, no Internet connection).

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.
 
Old 10-28-2013, 10:00 AM   #2
STDOUBT
Member
 
Registered: May 2010
Location: Stumptown
Distribution: Slackware64
Posts: 583

Rep: Reputation: 242Reputation: 242Reputation: 242
This one appears not to require a connection.
http://www.novaroma.org/via_romana/numbers.html

Just need a browser to display the page.
 
1 members found this post helpful.
Old 10-28-2013, 10:28 AM   #3
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
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.
 
2 members found this post helpful.
Old 10-28-2013, 10:49 AM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Original Poster
Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Quote:
Originally Posted by STDOUBT View Post
This one appears not to require a connection.
http://www.novaroma.org/via_romana/numbers.html

Just need a browser to display the page.
Oh, yeah! That doit toit, thanks!

Now all I have to do is get permission...
 
Old 10-28-2013, 10:52 AM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Original Poster
Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Quote:
Originally Posted by Didier Spaier View Post
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.

Thanks for input.
 
Old 10-28-2013, 10:38 PM   #6
perbh
Member
 
Registered: May 2008
Location: Republic of Texas
Posts: 393

Rep: Reputation: 81
The problem intrigued me - so I wrote a li'l c-program you can run from the command line ... so be my guest!
https://dl.dropboxusercontent.com/u/...19/roman2bin.c

Sadly, it doesn't do a reverse conversion :-(
 
Old 10-29-2013, 12:44 AM   #7
volkerdi
Slackware Maintainer
 
Registered: Dec 2002
Location: Minnesota
Distribution: Slackware! :-)
Posts: 2,503

Rep: Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461
Quote:
Originally Posted by perbh View Post
The problem intrigued me - so I wrote a li'l c-program you can run from the command line ... so be my guest!
https://dl.dropboxusercontent.com/u/...19/roman2bin.c

Sadly, it doesn't do a reverse conversion :-(
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

Enjoy!

Last edited by volkerdi; 10-29-2013 at 12:48 AM.
 
6 members found this post helpful.
Old 10-29-2013, 01:14 AM   #8
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
Seems to be an age-appropriate solution.
 
Old 10-29-2013, 01:19 AM   #9
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,222

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Here's a PyQt app I just knocked up. It needs the roman Python package to be installed.

Code:
#!/usr/bin/env python

from sip import setapi
setapi("QDate", 2)
setapi("QDateTime", 2)
setapi("QTextStream", 2)
setapi("QTime", 2)
setapi("QVariant", 2)
setapi("QString", 2)
setapi("QUrl", 2)


from PyQt4 import QtCore, QtGui
import roman
import sys


def main():
    app = QtGui.QApplication(sys.argv)
    view = ConversionWindow()
    conversionApp = Converter(view)
    conversionApp.show()
    sys.exit(app.exec_())


class ConversionWindow(QtGui.QDialog):

    def __init__(self, parent=None):
        super(ConversionWindow, self).__init__(parent)

        layout = QtGui.QVBoxLayout()
        form = QtGui.QFormLayout()
        self._roman = QtGui.QLineEdit()
        form.addRow('&Roman', self._roman)
        self._arabic = QtGui.QLineEdit()
        self._arabic.setReadOnly(True)
        form.addRow('&Arabic', self._arabic)
        layout.addLayout(form)
        self._convertButton = QtGui.QPushButton('Co&nvert')
        self._convertButton.setAutoDefault(True)
        layout.addWidget(self._convertButton)
        self.setLayout(layout)
        self.setWindowTitle('Roman to Arabic Numeral Converter')

    def connectSignals(self, converter):
        self._convertButton.clicked.connect(converter.convert)
        converter.arabic.connect(self._arabic.setText)

    def getRoman(self):
        return self._roman.text()


class Converter(QtCore.QObject):

    arabic = QtCore.pyqtSignal(unicode)

    def __init__(self, view):
        super(Converter, self).__init__(view)
        view.connectSignals(self)

    def show(self):
        self.parent().show()

    def convert(self):

        try:
            result = unicode(roman.fromRoman(self.parent().getRoman()))
        except roman.InvalidRomanNumeralError:
            result = ""

        self.arabic.emit(result)


if __name__ == '__main__':
    main()

Last edited by dugan; 10-29-2013 at 01:36 AM.
 
Old 10-29-2013, 01:26 AM   #10
volkerdi
Slackware Maintainer
 
Registered: Dec 2002
Location: Minnesota
Distribution: Slackware! :-)
Posts: 2,503

Rep: Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461
Quote:
Originally Posted by allend View Post
Seems to be an age-appropriate solution.
It does, doesn't it?

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.
 
Old 10-29-2013, 02:29 AM   #11
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
At least you didn't do it in Perl, which I consider to be the Devil's flatus.
 
Old 10-29-2013, 05:41 AM   #12
saulgoode
Member
 
Registered: May 2007
Distribution: Slackware
Posts: 288

Rep: Reputation: 155Reputation: 155
Quote:
Originally Posted by volkerdi View Post
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.
 
1 members found this post helpful.
Old 10-29-2013, 08:06 AM   #13
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Original Poster
Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Quote:
Originally Posted by volkerdi View Post
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.
 
Old 10-29-2013, 10:57 AM   #14
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,298
Blog Entries: 61

Rep: Reputation: Disabled
What did the Romans ever do for us?
 
Old 10-29-2013, 11:03 AM   #15
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Talking

Quote:
Originally Posted by brianL View Post
What did the Romans ever do for us?
They offered you King Mandubracius
 
  


Reply

Tags
numbers



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Numeral string compresion dth4h Programming 4 06-21-2012 09:17 PM
C++ Roman Numeral Converter ACSUSA Programming 3 02-24-2011 09:35 AM
'ls' .. or something to identify filenames that have a (space)(numeral) pattern rickh Programming 7 05-09-2006 01:51 AM
Times New Roman for Firefox? apachedude SUSE / openSUSE 0 11-30-2004 09:13 PM
Times New Roman-like fonts jrdioko Linux - Newbie 6 09-12-2004 07:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration