
Search

As of October, 2016, Embarcadero is offering a free release
of Delphi (Delphi
10.1 Berlin Starter Edition ). There
are a few restrictions, but it is a welcome step toward making
more programmers aware of the joys of Delphi. They do say
"Offer may be withdrawn at any time", so don't delay if you want
to check it out. Please use the
feedback link to let
me know if the link stops working.

Support DFF - Shop
If you shop at Amazon anyway, consider
using this link.
We receive a few cents from each
purchase. Thanks

Support DFF - Donate
If you benefit from the website, in terms of
knowledge, entertainment value, or something otherwise useful,
consider making a donation via PayPal to help defray the
costs. (No PayPal account necessary to donate via credit
card.) Transaction is secure.

Mensa®
Daily Puzzlers
For over 15 years
Mensa Page-A-Day calendars have provided several puzzles a year
for my programming pleasure. Coding "solvers" is most fun,
but many programs also allow user solving, convenient for "fill
in the blanks" type. Below are Amazon links to the
two most recent years.
Mensa®
365 Puzzlers Calendar 2017
Mensa®
365 Puzzlers Calendar 2018

(Hint: If you can
wait, current year calendars are usually on sale in January.)

Contact
Feedback:
Send an
e-mail with your comments about this program (or anything else).

|
| |
The Problem
Write a program to convert Arabic numbers less
than 4000 to Roman numeral notation and display the result.
Background & Techniques
A good chance to review your Roman
numeral knowledge. A quick Web search will turn up lots of good links to
refresh you.
After playing with a few numbers I noticed that
the digits 1 through 9 have the same pattern whether they are in the
unit's, ten's, hundred's or thousand's position ( thousands up to MMM). The actual
characters are different but the pattern is the same.
Units |
Tens |
Hundreds |
Thousands |
I |
X |
C |
M |
II |
XX |
CC |
MM |
III |
XXX |
CCC |
MMM |
IV |
XL |
CD |
MMMM |
V |
L |
D |
MMMMM |
VI |
LX |
DC |
MMMMMM |
VII |
LXX |
DCC |
etc. |
VIII |
LXXX |
DCCC |
|
IX |
XC |
CM |
|
If we make a table
containing the seven characters I, V, X, L, C, D, M, notice that the units digit
uses
only the first 3 characters (I. V, X), the tens digit uses 3rd
through 5th characters (X, L, C), and the hundreds digit uses the 5th
through 7th (C, D, M). The program uses this
consistent pattern. Check the code to see how.
Addendum October 8,2005: Finally got
around to adding number conversions from Roman back to Arabic at a user's
request. A bit more complicated because there are many ways to form
invalid Roman numerals using valid letters. In fact a random
collection of digits 1 through 9 will always form a valid Arabic number, but a
random collection of letters I, V, X, L, C, D, M is quite unlikely to form a
valid Roman number.
The lack of a zero placeholder is another
problem. Our conversion code needs to identify that no numeral is
defined for a particular position so we can insert the missing
zero.
Running/Exploring the Program
Suggestions for further exploration
 |
Try allowing Arabic numbers up to 9999. Notice
that above 3999, the leading 'M's just keep increasing. (There are
some other conventions using lines over the M's or some such,
but they didn't seem to adapt very well to machine display.) |
 |
Implemented
October, 2005: Another obvious
extension: Modify the program to convert Roman numerals back to
Arabic. (I haven't written this code yet - but I'll bet it's
possible.) |
Created: September 8, 2000 |
Modified: May 15, 2018
|
|