From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Roman - A Little Coding Challenge

I had a chance to participate in a coding challenge and came out pretty well. However, I know the brain power in BreakPoint is far superior and I wanted to put my code to the test. The original problem is:


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).

I wanted to test this by having it generate the list of 1-3999 and then convert all the numbers into Roman, then back into Arabic. I doubt I wrote it the fastest, and I doubt there's not a rube in there. So, if any of you want to take a crack at it and see if you can make the code simplier and faster.

 

Here's my solution (don't peak until you tried it)

 

 

Bruce

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

Message 1 of 13
(13,661 Views)

Well, that's a job for LookupTableMan, of course. 😄

 

(the reverse is a bit slow due to the linear search, so we should use variant attributes instead (not shown)).

0 Kudos
Message 2 of 13
(13,652 Views)

altenbach wrote:

(the reverse is a bit slow due to the linear search, so we should use variant attributes instead (not shown)).


With variant attributes, it is about twice as fast as yours (but a bit cryptic, codewise). 😄

0 Kudos
Message 3 of 13
(13,649 Views)

Here is an explicit decimal -> roman conversion. Seems about 25% faster than yours. More importantly, it is easier to read (only two cases!) and works directly off the numeric input.

 

0 Kudos
Message 4 of 13
(13,634 Views)

OK, here's my full code alternative for "Number to Roman String" and "Roman String to Number". Note that it is more universal and works fine for inputs >3999 (while yours fails for e.g. 4000).

 

It is about almost twice as fast on my PC (3.5ms vs. 6.5ms). I am sure it could be tweaked further. 😄

 

(Each conversion could be turned into a proper subVI for universal re-use. Of course it would need input checking and all the other expected stuff. :D)

0 Kudos
Message 5 of 13
(13,625 Views)

Just spent a few more minutes on this and found some simplifications. See if you can find them. 😉

0 Kudos
Message 6 of 13
(13,595 Views)

I would, but version 8.6 can't open 2012 files and I lack the space (and computing power) to install an updated version at present.

 

As an aside, http://en.wikipedia.org/wiki/Roman_numerals#Large_numbers is interesting.

0 Kudos
Message 7 of 13
(13,591 Views)

My attempt at Roman to Arabic numerals. Arabic to roman is alot simpler. 🙂 As the romans has no strict rules, the same number can be written in several ways, something you avoid with a arabic to roman generator. E.g. 9 can be ix, viiii or viv. My program actually translates them all. 😉

I haven't checked performance, but it should be fast enough.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 13
(13,488 Views)

I don't really have anything to contribute.  I just don't want the fact that Altenbach posted 5 times in a row to, go un-noticed.  Maybe that's how he got his 20K+ medal.  

 

(know that I mean no disrespect and this is intended to be a joke, this is BreakPoint after all)

0 Kudos
Message 9 of 13
(13,424 Views)

@Hooovahh wrote:

I just don't want the fact that Altenbach posted 5 times in a row to, go un-noticed.  Maybe that's how he got his 20K+ medal.  


My posts are far apart in time. It is not my fault if the rest of the community fails to contribute 😄

Message 10 of 13
(13,415 Views)