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.

Forum Statistics

Users
Members:
543
Members Online:
9
Guests Online:
5

Total Post History
Posts:
45705
Topics:
9398

7-Day Post History
New Posts:
343
New Topics:
81
Active Topics:
90

Our newest member
sangeeta

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!
And we have contraptions like computers that cheat you out of becoming. Bill Gates says, "Wait till you see what your computer can become." But it's you who should be doing the becoming, not the damn fool computer.

My Crummy Web Page
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
 
Posts: 3532
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: 119LTD Bronze - Rating: 119LTD Bronze - Rating: 119
 
Posts: 645
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: 119LTD Bronze - Rating: 119LTD Bronze - Rating: 119
 
Posts: 645
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: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264
LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264
LTD Gold - Rating: 1264
 
Posts: 6038
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:
And we have contraptions like computers that cheat you out of becoming. Bill Gates says, "Wait till you see what your computer can become." But it's you who should be doing the becoming, not the damn fool computer.

My Crummy Web Page
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
 
Posts: 3532
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: 119LTD Bronze - Rating: 119LTD Bronze - Rating: 119
 
Posts: 645
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: 119LTD Bronze - Rating: 119LTD Bronze - Rating: 119
 
Posts: 645
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: 427LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427
LTD Silver - Rating: 427LTD Silver - Rating: 427
 
Posts: 3160
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: 119LTD Bronze - Rating: 119LTD Bronze - Rating: 119
 
Posts: 645
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: 427LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427
LTD Silver - Rating: 427LTD Silver - Rating: 427
 
Posts: 3160
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: 484LTD Silver - Rating: 484LTD Silver - Rating: 484LTD Silver - Rating: 484LTD Silver - Rating: 484
LTD Silver - Rating: 484LTD Silver - Rating: 484LTD Silver - Rating: 484
 
Posts: 1986
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: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264
LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264
LTD Gold - Rating: 1264
 
Posts: 6038
Joined: Wed Oct 10, 2007 7:18 pm
Location: Belgium
Unrated