06-24-2015 01:15 PM - edited 06-24-2015 01:17 PM
While you are playing with big numbers, have a look at the results of the old factorial challenge. The top contenders were able to calculate 10000! (10000 factorial), a result with 35,659 decimal digits in less than 100 milliseconds. This was back in 2004, and computers are much faster today.
You problem is much simpler! 😄
(... and why are you using value property nodes??? Just branch the wire!)
06-25-2015 10:18 AM
Just for "fun", I decided to take my own suggestion and write a Big Number project to handle Addition and Multiplication of Arbitrarily-Long Integers. I built in "sign" handling for Multiplication, but (in the interest of getting a "testable") I currently only support non-negative Addition (and no Subtraction, yet -- it should be a fairly easy, and you'll forgive the accidental pun, Add-On). The Project has 11 sub-VIs, including Product, Sum, and Power, plus one designed for output called "Big Number String" (currently only a Decimal string is supported). I was not necessarily "coding for speed of execution", but rather for clarity of operation and ease of "proving that this works".
I tried it out on your problem. I got out a 135-digit decimal number that appears to match what you posted as the Correct Answer (it starts with 76677477 ... and ends with ...35294157). It executes in about 20 milliseconds.
Just for fun, I also coded up a computation of 10000! (after reading Altenbach's post). I was not aware of the Factorial Challenge, and haven't look at the Post he cited, so am unsure how my algorithm compares with the 100-millisecond champ. I'm definitely slower -- about 37 seconds, and while I didn't print out the result, I got 35,660 digits, one more than what is noted in Christian's Post. However, you can Google Factorial 10000 and find its value posted on the Web -- my answer agrees with the posted value for the first (most-significant) 20-or-so digits that I compared.
For the time being, I'm going to skip over how to convert this monster decimal string representation of a number to a hex representation -- my suspicion is that it will be easier to write a Hex Package to do the same calculation (and to define an inherently Hexy format to store the arbitrary-precision number) than to try to write a direct Conversion routine. I'll leave this task (as well as creating one's own Big Number Project) as an "Exercise for the Reader". Consider this an Existence Proof.
Bob Schor
06-25-2015 10:33 AM
@Bob_Schor wrote:
Just for fun, I also coded up a computation of 10000! (after reading Altenbach's post). I was not aware of the Factorial Challenge, and haven't look at the Post he cited, so am unsure how my algorithm compares with the 100-millisecond champ. I'm definitely slower -- about 37 seconds, and while I didn't print out the result, I got 35,660 digits, one more than what is noted in Christian's Post. However, you can Google Factorial 10000 and find its value posted on the Web -- my answer agrees with the posted value for the first (most-significant) 20-or-so digits that I compared.
You can look at my link, there is no usable code visible. 😉
I have to dig out my old code, but is was definitely correct. I got the quoted number of digits from google, not from my old code, so I am not sure what value is correct. More fun would be the modulo operation and I think I made one for the vampire number challenge, but once you can do extra-long multiplications, it is just a small additional step. I am pretty sure that my current computer would do 10000! in the low tens of millisecnds. We'll see...
06-25-2015 11:30 AM
06-25-2015 11:47 AM
Good, at least the answer is correct (if slow by 3-4 orders of magnitude).
BS
06-25-2015 12:17 PM - edited 06-25-2015 12:21 PM
@Bob_Schor wrote:
Good, at least the answer is correct (if slow by 3-4 orders of magnitude).
I guess your code is also smaller by a few orders of magnitude.... 😄 (note that there is also a subVI call somewhere, so there is more ....)
The 8.3ms elapsed time includes the formatting of the output string, of course. I am sure I could make it faster nowadays. 😉
06-25-2015 03:36 PM
I'm not looking, I'm not looking ... I've been thinking about Speed Improvement, and have some ideas to try out. I've got a few other things on my plate ("real work"), so it may be a few days until I revisit this ...
BS
06-25-2015 03:43 PM
@Bob_Schor wrote:
I'm not looking, I'm not looking ...
No worries, the code picture is to small to be recognizable. Well, you can count five main stages, but that's about it.
Also remember that Bruce Ammons was slightly faster using a more intelligent algorithm. Mine is pretty much brute force. 😉
06-25-2015 03:51 PM
@altenbach wrote:
@Bob_Schor wrote:
Good, at least the answer is correct (if slow by 3-4 orders of magnitude).
I guess your code is also smaller by a few orders of magnitude....
It is fairly compact. Note that I wasn't using any "intelligence" directed at the problem of optimizing for speed, I just did a Brute Force (= slow) cumulative multiply ...
The first step, of course, is completely unnecessary (1 * 1 = 1, after all), but that's not going to amount to a Hill of Beans in the timing ...
BS
06-25-2015 06:52 PM - edited 06-25-2015 07:07 PM