Login or Sign Up to become a member!
LessThanDot Site 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 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:
1590
Members Online:
3
Guests Online:
7

Total Post History
Posts:
80550
Topics:
18446

7-Day Post History
New Posts:
7
New Topics:
1
Active Topics:
7

Our newest member
langm8029

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!
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5411
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: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231
 
Posts: 1141
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: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231
 
Posts: 1141
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.
pink fuzzy slippers
User avatar
chrissie1
Senior Guru
Senior Guru
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088
 
Posts: 9348
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:
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5411
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: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231
 
Posts: 1141
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: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231
 
Posts: 1141
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:
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948
 
Posts: 5302
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: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231LTD Bronze - Rating: 231
 
Posts: 1141
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! :)
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948
 
Posts: 5302
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: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
 
Posts: 2492
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: 62LTD Bronze - Rating: 62
 
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.
pink fuzzy slippers
User avatar
chrissie1
Senior Guru
Senior Guru
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088
 
Posts: 9348
Joined: Wed Oct 10, 2007 7:18 pm
Location: Belgium
Unrated

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

Postby paulasmuth on Tue Jan 03, 2012 10:07 pm

I think I'll just leave this here...

Code is hidden, SHOW
paulasmuth
Newbie
Newbie
LTD Bronze - Rating: 9
 
Posts: 2
Joined: Tue Jan 03, 2012 10:04 pm

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

Postby paulasmuth on Fri Feb 24, 2012 3:05 am

And in Scala (no mutable state)

Code is hidden, SHOW
paulasmuth
Newbie
Newbie
LTD Bronze - Rating: 9
 
Posts: 2
Joined: Tue Jan 03, 2012 10:04 pm

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

Postby biglittle007 on Wed Aug 21, 2013 4:50 pm

My php code:

Code is hidden, SHOW
biglittle007
Newbie
Newbie
 
Posts: 3
Joined: Wed Aug 14, 2013 9:16 pm
Unrated

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

Postby Kermit on Thu Aug 22, 2013 5:16 pm

Where are all the perl kids when you want to see what hell looks like in code.

Shamsm, that's what I like about Java...if it was a real person and you asked it for a name, it would give you a lengthy discussion.

Here is my attempt using (wait for it) bbcode:

"omg who uses roman numerals, learn 2 countz doh!!11"
MotherFbleeper
User avatar
Kermit
LTD Admin
LTD Admin
LTD Bronze - Rating: 92LTD Bronze - Rating: 92
 
Posts: 523
Joined: Thu Oct 11, 2007 11:14 am
Location: United Kingdom
Unrated