Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Int to Roman Numeral script

Author
Message
Arachaic
9
Years of Service
User Offline
Joined: 13th Dec 2010
Location:
Posted: 13th Dec 2010 17:52
I have searched everywhere and cant find a gdk code for a number to roman numeral converter. I know you would have to convert the number to string but other then that i dunno were to start can i get the code for the converter or sent in the right direction?
BN2 Productions
16
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 13th Dec 2010 20:06 Edited at: 13th Dec 2010 22:27
Well gdk isn't really our thing here, this is the DarkBASIC Classic forum.

That being said, my initial approach here would be to find the values of each digit of the number. Easy way would be to declare an array with as many slots as there are digits (convert the number to a string and check the number of characters). Once there you can figure out the appropriate roman numerals for each digit.

I will try to throw some DBC code together as an example (this seems like an interesting challenge).

[EDIT]
Alright, since you will be translating, I threw in plenty of comments so that you can understand WHAT is going on and why and how it works and all that jazz. BTW, thanks. This was a pretty fun little challenge.



Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Dec 2010 00:26
In the DBC challenges there was a roman to arabic numeral conversion challenge. It might be worth checking out

Enjoy your day.
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Dec 2010 16:34 Edited at: 15th Dec 2010 17:00
I tried searching for our entries to the Roman Numerals Challenge but couldn't find them. Thank Phaelax for his great site recording all the DBC Challenges: [href]http://dbcc.zimnox.com/?page=view&challenge=Roman to Arabic[/href]

Mine uses a load of nested IFs which I thought was a good idea because it doesn't require an array, but this method is really messy and difficult to read, an array would tidy it up.
I think I'll have a quick go at writing another version of this...



This doesn't actually work properly because 3 would be displayed as IIV, which sort of works but isn't a proper roman number. I'm running out of time though so I'll leave it at that.


Snobbery is a privilege of the ignorant.
BN2 Productions
16
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 15th Dec 2010 21:34
Numbers>4000 will present a challenge (I just retrofitted my code to handle it) as it switches from MMMM to (IV) and continues counting. Alternatively you can draw a line above the numbers, but parenthesis are easier here. They essentially mean "multiply everything in here by 1000".

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 15th Dec 2010 23:26 Edited at: 15th Dec 2010 23:28
In the actual challenge thread, the roman to arabic challenge appears around page 86 the way my forum settings are. It all depends on how many posts you have set to display on a page.

Enjoy your day.
Phaelax
DBPro Master
17
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Dec 2010 09:59
http://dbcodecorner.com/?page=view&challenge=Roman%20to%20Arabic

Looks like OBese was taking a similar approach to mine:


"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein

Login to post a reply

Server time is: 2020-08-12 02:59:09
Your offset time is: 2020-08-12 02:59:09