08-13-2013 02:00 PM
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
"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
08-13-2013 02:32 PM
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)).
08-13-2013 02:40 PM
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). 😄
08-13-2013 03:25 PM
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.
08-13-2013 04:33 PM
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)
08-13-2013 11:36 PM
Just spent a few more minutes on this and found some simplifications. See if you can find them. 😉
08-14-2013 12:09 AM
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.
08-18-2013 08:24 AM
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
08-20-2013 12:22 PM
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)
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
08-20-2013 01:03 PM
@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 😄