Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

A Technical Community for IT Professionals

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Forum Statistics

Users
Members:
705
Members Online:
2
Guests Online:
4

Total Post History
Posts:
56484
Topics:
11714

7-Day Post History
New Posts:
373
New Topics:
62
Active Topics:
76

Our newest member
lupets0011

Other

FAQ
All times are UTC [ DST ]

Google Ads

LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Mind Boggling Puzzles, to keep that grey matter in shape...
Forum rules
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Please wait...

LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby AlexCuse on Fri Jul 25, 2008 4:57 pm

The puzzle this week is simple.

Write a program to convert to (and from) roman numerals. So your program should be able to take the input of 27 and return XXVII, and take MCMLXXXI and return 1981. And of course any other values.

The program must work for all numbers between the upper bound of 4000 and the lower bound of 0 (both non-inclusive)

Bonus points if you check incoming roman numerals for well-formedness (this lists some of the rules: http://en.wikipedia.org/wiki/Roman_nume ... n_numerals)

Have Fun!
In all branches of the economy they brandished their formulas and calculations and refused to understand that bridges and lathes could respond to the enthusiasm of the personnel.

My Crummy Web Page
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747
LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747
 
Posts: 4278
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US
Unrated

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby LNBruno on Fri Jul 25, 2008 6:25 pm

Okay, so I had this squirreled away in my bag of tricks...(2000)

Code is hidden, SHOW
M!ke
God is great. Beer is good. People are crazy.
User avatar
LNBruno
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150
 
Posts: 812
Joined: Thu Oct 18, 2007 9:00 pm
Location: Charlotte, NC

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby LNBruno on Fri Jul 25, 2008 6:26 pm

Rats! Left off the final END in the first blob o' code.
M!ke
God is great. Beer is good. People are crazy.
User avatar
LNBruno
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150
 
Posts: 812
Joined: Thu Oct 18, 2007 9:00 pm
Location: Charlotte, NC
Unrated

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby chrissie1 on Fri Jul 25, 2008 7:09 pm

LNBruno wrote:Rats! Left off the final END in the first blob o' code.


you can edit your code. Like me ;-) I made it a hidecode tags instead of hide tags.
User avatar
chrissie1
LTD Admin
LTD Admin
LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472
LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472
LTD Gold - Rating: 1472
 
Posts: 7045
Joined: Wed Oct 10, 2007 7:18 pm
Location: Belgium
Unrated

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby AlexCuse on Fri Jul 25, 2008 7:12 pm

Mike, please tell me it was squirelled away from a past puzzle, and not production code :lol:
In all branches of the economy they brandished their formulas and calculations and refused to understand that bridges and lathes could respond to the enthusiasm of the personnel.

My Crummy Web Page
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747
LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747LTD Silver - Rating: 747
 
Posts: 4278
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US
Unrated

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby LNBruno on Fri Jul 25, 2008 7:26 pm

Hey, cool! Didn't know I could edit my post, chrissie! Thanks.

And Alex, of course it was from a past puzzle! Definitely, absolutely not, I repeat, NOT any production code I ever had to write...

Okay, okay! I confess! It was production code. :crybaby:
M!ke
God is great. Beer is good. People are crazy.
User avatar
LNBruno
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150
 
Posts: 812
Joined: Thu Oct 18, 2007 9:00 pm
Location: Charlotte, NC
Unrated

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby LNBruno on Fri Jul 25, 2008 7:28 pm

DOH! Edit button, ID10T!

Did I mention that I'm glad it's Friday?
M!ke
God is great. Beer is good. People are crazy.
User avatar
LNBruno
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150
 
Posts: 812
Joined: Thu Oct 18, 2007 9:00 pm
Location: Charlotte, NC
Unrated

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby Remou on Fri Jul 25, 2008 7:58 pm

LNBruno wrote:Hey, cool! Didn't know I could edit my post, chrissie! Thanks.

And Alex, of course it was from a past puzzle! Definitely, absolutely not, I repeat, NOT any production code I ever had to write...

Okay, okay! I confess! It was production code. :crybaby:


Do you use papiri or wax tablets for your code?

:old:
x
User avatar
Remou
LTD Admin
LTD Admin
LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596
LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596
 
Posts: 3769
Joined: Sun Oct 14, 2007 11:26 am
Unrated

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby LNBruno on Fri Jul 25, 2008 8:34 pm

Remou asked: Do you use papiri or wax tablets for your code?


We're still on Stone Tablets (beta). :D
M!ke
God is great. Beer is good. People are crazy.
User avatar
LNBruno
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150LTD Bronze - Rating: 150
 
Posts: 812
Joined: Thu Oct 18, 2007 9:00 pm
Location: Charlotte, NC
Unrated

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby Remou on Fri Jul 25, 2008 8:36 pm

Ooh! Silicon chips! :)
x
User avatar
Remou
LTD Admin
LTD Admin
LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596
LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596LTD Silver - Rating: 596
 
Posts: 3769
Joined: Sun Oct 14, 2007 11:26 am
Unrated

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby ca8msm on Tue Jul 29, 2008 3:34 pm

Here's an ASP.NET version:
Code is hidden, SHOW
User avatar
ca8msm
LTD Admin
LTD Admin
LTD Silver - Rating: 592LTD Silver - Rating: 592LTD Silver - Rating: 592LTD Silver - Rating: 592LTD Silver - Rating: 592
LTD Silver - Rating: 592LTD Silver - Rating: 592LTD Silver - Rating: 592LTD Silver - Rating: 592
 
Posts: 2309
Joined: Wed Oct 10, 2007 6:49 pm
Location: North East England

A solution in java using enums

Postby shamsm on Wed Jul 30, 2008 10:20 am

Here is a solution in java which does some validation on the roman input,
the roman digits are represented by enums

Code is hidden, SHOW
shamsm
Apprentice
Apprentice
LTD Bronze - Rating: 47
 
Posts: 12
Joined: Wed Jul 30, 2008 10:09 am

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby b3orn on Wed Jul 30, 2008 11:44 am

My solution. Not fully completed (some checks should be implemented) but it (seems to) works. I used some test from shamsm (thanks).

Code is hidden, SHOW
b3orn
Apprentice
Apprentice
LTD Bronze - Rating: 37
 
Posts: 9
Joined: Thu Jul 17, 2008 3:23 pm

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby tisodotsk on Fri Aug 08, 2008 1:00 pm

PHP, quick and dirty (without validations):
Code is hidden, SHOW

Output, first 10 lines:
  1. 1 -> I -> 1
  2. 2 -> II -> 2
  3. 3 -> III -> 3
  4. 4 -> IV -> 4
  5. 5 -> V -> 5
  6. 6 -> VI -> 6
  7. 7 -> VII -> 7
  8. 8 -> VIII -> 8
  9. 9 -> IX -> 9
  10. 10 -> X -> 10
Last edited by tisodotsk on Fri Aug 08, 2008 1:14 pm, edited 1 time in total.
I try to improve my English language skills. Most things i do better than this.
tisodotsk
Apprentice
Apprentice
LTD Bronze - Rating: 59LTD Bronze - Rating: 59
 
Posts: 22
Joined: Fri Aug 08, 2008 12:45 pm
Location: Bratislava, Slovakia

Re: LTD Puzzle VIII - Convert Between Roman and Arabic Numerals

Postby chrissie1 on Fri Aug 08, 2008 1:08 pm

Validation is for sissies ;-)

You just have to select smarter users.
User avatar
chrissie1
LTD Admin
LTD Admin
LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472
LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472LTD Gold - Rating: 1472
LTD Gold - Rating: 1472
 
Posts: 7045
Joined: Wed Oct 10, 2007 7:18 pm
Location: Belgium
Unrated