Welcome to the Fonality Perl Golf Challenge

What is Perl Golf?

Perl Golf is a competition to find the shortest (fewest keystrokes) Perl code to solve a given problem

Careers at Fonality

If you're interested in a Perl position, engineering position, or any other careers at Fonality, check out our careers page here!
The Challenge:
In a nutshell, this is a Roman Numeral Calculator.

The program will take a single line of input containing upper-case Roman Numerals with the words `" plus "` or `" minus "` between them. The challenge is to create a Perl program in as few characters as possible to perform the calculation and print out the answer in Roman Numerals back to the screen.

The program is a filter: it must read from STDIN, and send output to STDOUT.

• Input will consist of a single line, which will match `/\A[IVXLCDM]+( (plus|minus) [IVXLCDM]+){1,3}\n\z/`. This means that the input will consist of three to seven words separated by single spaces.

• The input will be between two and four upper-case Roman Numerals between `I` and `MMMCMXCIX` (1 to 3999) joined by `plus` or `minus`, all separated by a single space. Your program need not test the input for validity, and its behavior on invalid input is not important.

• The output should be a single line, matching `/\A[IVXLCDM]+\n\z/`, and be the Roman Numeral representation of the calculation. The output will be between I (1) and MMMCMXCIX (3999).

• Roman Numerals will always be in upper-case and in short-hand form. For example, you will always receive an input of `"IV"` rather than `"IIII"`. You must also always output `"IV"` rather than `"IIII"`.

• At no time during the various math operations will a number be less than I (1) or greater than MMMCMXCIX (3999). That means you will never have a calculation such as "I minus V plus X". Even though the output is >= I (1) and <= MMMCMXCIX (3999), during the process (I minus V) becomes < I (1) which is not allowed.

• You may not use any Perl modules.

• Anyone, anywhere is able to play and win!

• More information on Roman Numerals can be found at Wolfram MathWorld.

All additional rules that apply to this challenge can be found here.

 Roman Numerals I = 1 C = 100 V = 5 D = 500 X = 10 M = 1000 L = 50

A test program to test output of your program is provided here.

Rules:

The basic rules are under "The Challenge" section of this page. Be sure to read all of the additional, generic Perl golf rules here.

Post-Mortem:

You can view the post-mortem here.

Submitting:

The deadline for this challenge is January 1st, 2007, 11:59 pm PST.

Tiebreaker:

The tiebreaker will favor programs with fewer alphanumeric, whitespace and underscore characters.

Test Program:

A test program to test output of your program is provided here.

Examples:

 \$ perl romancalc.pl in: I plus I out: II
 \$ perl romancalc.pl in: MDCCCXXIV plus DCCVI out: MMDXXX
 \$ perl romancalc.pl in: MCCXIII minus LXIV plus MMDXXX out: MMMDCLXXIX
 \$ perl romancalc.pl in: MMXIX plus MCCCXCVI minus DCXCV plus CI out: MMDCCCXXI
 Place Prizes 1st USD \$350.00 (Cash) 2nd USD \$175.00 (Cash) 3rd USD \$125.00 (Cash) 4th USD \$75.00 (Cash) 5th USD \$50.00 (Cash) 6th USD \$25 Gift Certificate (Amazon) 7th USD \$25 Gift Certificate (Amazon) 8th USD \$25 Gift Certificate (Amazon) 9th USD \$25 Gift Certificate (Amazon) 10th USD \$25 Gift Certificate (Amazon) 11th USD \$25 Gift Certificate (Amazon) 12th USD \$25 Gift Certificate (Amazon) 13th USD \$25 Gift Certificate (Amazon) 14th USD \$25 Gift Certificate (Amazon) 15th Fonality or trixbox T-Shirt 16th Fonality or trixbox T-Shirt 17th Fonality or trixbox T-Shirt 18th Fonality or trixbox T-Shirt 19th Fonality or trixbox T-Shirt 20th Fonality or trixbox T-Shirt

Questions: