Author |
Message |
Mark Keog #1 / 16
|
 Factorial of 10000
Ok, I've been issued the challenge to get the above. THe problemis what should I store the result as? The returned number, verified in Smalltalk, is a 36000 and something digit int! Any ideas?
|
Tue, 04 Feb 2003 08:59:52 GMT |
|
 |
Drac #2 / 16
|
 Factorial of 10000
released on Fri, 18 Aug 2000 10:59:52 +1000 bearing the following fruit: Quote: >Ok, >I've been issued the challenge to get the above. THe problemis what should I >store the result as? The returned number, verified in SmallTalk, is a 36000 >and something digit int! >Any ideas?
Isn't the factorial of 3 = 3 * 2 * 1 = 6 ? Because if it is then 36,000 certainly isn't the factorial of 10,000 The windows calculator has a factorial function, take a look for a more realistic value. D
|
Tue, 04 Feb 2003 03:00:00 GMT |
|
 |
rumpol #3 / 16
|
 Factorial of 10000
Quote: >>The returned number, verified in SmallTalk, is a 36000 >>and something digit int! >Isn't the factorial of 3 = 3 * 2 * 1 = 6 ? >Because if it is then 36,000 certainly isn't >the factorial of 10,000 >The windows calculator has a factorial function, >take a look for a more realistic value.
maybe if he'd said "an integer with 36000+ digits" you wouldn't have misread it?
|
Tue, 04 Feb 2003 03:00:00 GMT |
|
 |
Ron Lessnic #4 / 16
|
 Factorial of 10000
Do a search on the binary coded decimal system (BCD). Each decimal digit position is stored as 4 bits. Thus a byte will hold two digits. So an integer of length 36000 decimal digits long can be stored in a 18K byte array. So to display the BIG answer you loop thru the array decoding each byte into its two equivalent decimals and build up a string of VERY LONG length shove it in multiline enabled scrollable text box and you are home free. Real challenge will be the coding to do the multiplication of BCD numbers, but maybe there is some math library (dll) you can find. HTH Ron
Quote: > Ok, > I've been issued the challenge to get the above. THe problemis what should I > store the result as? The returned number, verified in SmallTalk, is a 36000 > and something digit int! > Any ideas?
|
Tue, 04 Feb 2003 03:00:00 GMT |
|
 |
Gale Gree #5 / 16
|
 Factorial of 10000
Hi. Quote: >Isn't the factorial of 3 = 3 * 2 * 1 = 6 ? >Because if it is then 36,000 certainly isn't >the factorial of 10,000
I think you missed a vital word in Mark's post - it isn't a 36,000-odd number, it's a 36,000-odd *digit* number! I'm sure I could devise an algorithm but I'm afraid life's too short and clients are too demanding. <g> Gale.
|
Tue, 04 Feb 2003 03:00:00 GMT |
|
 |
Drac #6 / 16
|
 Factorial of 10000
released on Fri, 18 Aug 2000 13:45:06 +0100 bearing the following fruit: Quote: >Hi. >>Isn't the factorial of 3 = 3 * 2 * 1 = 6 ? >>Because if it is then 36,000 certainly isn't >>the factorial of 10,000 >I think you missed a vital word in Mark's post - it isn't a 36,000-odd >number, it's a 36,000-odd *digit* number! >I'm sure I could devise an algorithm but I'm afraid life's too short >and clients are too demanding. <g> >Gale.
Yep, as rumpole suggests, I did misunderstand what was written. <bows head in shame> D
|
Tue, 04 Feb 2003 03:00:00 GMT |
|
 |
Brent W.J. Macki #7 / 16
|
 Factorial of 10000
10000! = 2.8462596809170545189064132121 x 10^35659 As verified using Calc.exe on Win98SE Brent
Quote:
> released on Fri, 18 Aug 2000 10:59:52 +1000 bearing the > following fruit: > >Ok, > >I've been issued the challenge to get the above. THe problemis what should I > >store the result as? The returned number, verified in SmallTalk, is a 36000 > >and something digit int! > >Any ideas? > Isn't the factorial of 3 = 3 * 2 * 1 = 6 ? > Because if it is then 36,000 certainly isn't > the factorial of 10,000 > The windows calculator has a factorial function, > take a look for a more realistic value. > D
|
Tue, 04 Feb 2003 03:00:00 GMT |
|
 |
Mark Heat #8 / 16
|
 Factorial of 10000
A simple way is to use strings to store your numbers and multiply as though you were doing it by hand. There are, of course, much more efficient ways than this but this should point you in the right sort of direction. Mark Public Function Multiply(arg1 As String, arg2 As String) As String Dim i As Integer Dim j As Integer Dim str1 As String Dim str2 As String Dim strTotal As String Dim strTemp As String Dim iCarry As Integer Dim iTemp As Integer str1 = StrReverse(arg1) str2 = StrReverse(arg2) For i = 1 To Len(str1) iCarry = 0 strTemp = String(i - 1, "0") For j = 1 To Len(str2) iTemp = CInt(Mid$(str2, j, 1)) * CInt(Mid$(str1, i, 1)) + iCarry strTemp = strTemp & (iTemp Mod 10) iCarry = iTemp \ 10 Next j If iCarry > 0 Then strTemp = strTemp & iCarry End If strTotal = AddRevString(strTotal, strTemp) Next i Multiply = StrReverse(strTotal) End Function Public Function AddRevString(arg1 As String, arg2 As String) As String Dim i As Integer Dim strTotal As String Dim iCarry As Integer Dim iMax As Integer Dim iTemp As Integer iMax = Len(arg1) If Len(arg2) > iMax Then iMax = Len(arg2) End If iCarry = 0 For i = 1 To iMax iTemp = Val(Mid$(arg2, i, 1)) + Val(Mid$(arg1, i, 1)) + iCarry strTotal = strTotal & (iTemp Mod 10) iCarry = iTemp \ 10 Next i If iCarry > 0 Then strTotal = strTotal & iCarry End If AddRevString = strTotal End Function
Quote: > Ok, > I've been issued the challenge to get the above. THe problemis what should I > store the result as? The returned number, verified in SmallTalk, is a 36000 > and something digit int! > Any ideas?
|
Tue, 04 Feb 2003 03:00:00 GMT |
|
 |
Mark Heat #9 / 16
|
 Factorial of 10000
I ought to point out that this will take ages to calculate factorial 10000 (quite possibly a couple of days - depending on your computer speed) If you can program in C you will be able to speed this up considerably. Mark
Quote: > A simple way is to use strings to store your numbers and multiply as though > you were doing it by hand. > There are, of course, much more efficient ways than this but this should > point you in the right sort of direction. > Mark > Public Function Multiply(arg1 As String, arg2 As String) As String > Dim i As Integer > Dim j As Integer > Dim str1 As String > Dim str2 As String > Dim strTotal As String > Dim strTemp As String > Dim iCarry As Integer > Dim iTemp As Integer > str1 = StrReverse(arg1) > str2 = StrReverse(arg2) > For i = 1 To Len(str1) > iCarry = 0 > strTemp = String(i - 1, "0") > For j = 1 To Len(str2) > iTemp = CInt(Mid$(str2, j, 1)) * CInt(Mid$(str1, i, 1)) + iCarry > strTemp = strTemp & (iTemp Mod 10) > iCarry = iTemp \ 10 > Next j > If iCarry > 0 Then > strTemp = strTemp & iCarry > End If > strTotal = AddRevString(strTotal, strTemp) > Next i > Multiply = StrReverse(strTotal) > End Function > Public Function AddRevString(arg1 As String, arg2 As String) As String > Dim i As Integer > Dim strTotal As String > Dim iCarry As Integer > Dim iMax As Integer > Dim iTemp As Integer > iMax = Len(arg1) > If Len(arg2) > iMax Then > iMax = Len(arg2) > End If > iCarry = 0 > For i = 1 To iMax > iTemp = Val(Mid$(arg2, i, 1)) + Val(Mid$(arg1, i, 1)) + iCarry > strTotal = strTotal & (iTemp Mod 10) > iCarry = iTemp \ 10 > Next i > If iCarry > 0 Then > strTotal = strTotal & iCarry > End If > AddRevString = strTotal > End Function
> > Ok, > > I've been issued the challenge to get the above. THe problemis what should > I > > store the result as? The returned number, verified in SmallTalk, is a > 36000 > > and something digit int! > > Any ideas?
|
Tue, 04 Feb 2003 03:00:00 GMT |
|
 |
Ron #10 / 16
|
 Factorial of 10000
Since it takes about 5 seconds for Calc.exe to come up with that number one has to assume the result is from Stirlings formula which is only an "approximation" for large numbers. To do this calculation for real would take ALOT longer. Also I assume the original poster wanted to do it in VB Ron
Quote: > 10000! = 2.8462596809170545189064132121 x 10^35659 > As verified using Calc.exe on Win98SE > Brent
> > released on Fri, 18 Aug 2000 10:59:52 +1000 bearing the > > following fruit: > > >Ok, > > >I've been issued the challenge to get the above. THe problemis what > should I > > >store the result as? The returned number, verified in SmallTalk, is a > 36000 > > >and something digit int! > > >Any ideas? > > Isn't the factorial of 3 = 3 * 2 * 1 = 6 ? > > Because if it is then 36,000 certainly isn't > > the factorial of 10,000 > > The windows calculator has a factorial function, > > take a look for a more realistic value. > > D
______________________________________________________________________ Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.*-*-*.com/ With Servers In California, Texas And {*filter*}ia - The Worlds Uncensored News Source
|
Wed, 05 Feb 2003 03:00:00 GMT |
|
 |
Scott Seligma #11 / 16
|
 Factorial of 10000
Quote: > I've been issued the challenge to get the above. THe problemis what should I > store the result as? The returned number, verified in SmallTalk, is a 36000 > and something digit int!
Well, if the challenge doesn't specify a time limit, then the easist solution is store the number as a string, and write a couple of functions that can multiple and add strings (without converting the whole number to an intrinsic type, but rather adding as a normal person would have to add or multiply a big number). I just wrote a little program that did this, and to find the factorial of 10,000 took a few hours, but it does work. To speed things up, you generally take the same idea, but instead of creating a long string like "123123", you create an array of numbers, say using the byte type, and treat your big number as a base 255 number. This way each entry in the array is one digit of the number The trick becoms to convert a big number like this into a base 10 number. There are books that describe this technique, and have some code showing how it's done (mostly in C/C++ though). Hope this helps. -- Scott
|
Wed, 05 Feb 2003 03:00:00 GMT |
|
 |
Jeff Ashle #12 / 16
|
 Factorial of 10000
Quote: > The trick becoms to convert a big number like this into a base 10 number.
No kidding! I've never used base 255 . . .
|
Wed, 05 Feb 2003 03:00:00 GMT |
|
 |
Arie Bakke #13 / 16
|
 Factorial of 10000
Is your problem solved? I've made some years ago a program to calculate 2^300 and that must be about the same problem. I can look for it, if your problem isn't solved yet. Please send a e-mail if you need it. Arie Bakker Quote:
> Ok, > I've been issued the challenge to get the above. THe problemis what should I > store the result as? The returned number, verified in SmallTalk, is a 36000 > and something digit int! > Any ideas?
|
Fri, 07 Feb 2003 07:08:24 GMT |
|
 |
Rui Martins dos Santo #14 / 16
|
 Factorial of 10000
Windows 2000 Calc: 10000! = 2,8462596809170545189064132121199e+35659
Quote: > 10000! = 2.8462596809170545189064132121 x 10^35659 > As verified using Calc.exe on Win98SE > Brent
> > released on Fri, 18 Aug 2000 10:59:52 +1000 bearing the > > following fruit: > > >Ok, > > >I've been issued the challenge to get the above. THe problemis what > should I > > >store the result as? The returned number, verified in SmallTalk, is a > 36000 > > >and something digit int! > > >Any ideas? > > Isn't the factorial of 3 = 3 * 2 * 1 = 6 ? > > Because if it is then 36,000 certainly isn't > > the factorial of 10,000 > > The windows calculator has a factorial function, > > take a look for a more realistic value. > > D
|
Fri, 07 Feb 2003 03:00:00 GMT |
|
 |
Jeff Ashle #15 / 16
|
 Factorial of 10000
Well, that's a fair approximation . . .
Quote: > Windows 2000 Calc: > 10000! = 2,8462596809170545189064132121199e+35659
|
Fri, 07 Feb 2003 03:00:00 GMT |
|
|
Page 1 of 2
|
[ 16 post ] |
|
Go to page:
[1]
[2] |
|