
-----------------------------------
randint
Mon Oct 29, 2012 3:55 pm

Factorial Function Unlimited
-----------------------------------
This factorial function is identical to what I built previously except that the input is limited by only the RAM avaliable to the Java Virtual Machine, it uses arbitrary-precision integers to calculate, it is super slow but it works!

-----------------------------------
mirhagk
Tue Oct 30, 2012 9:58 am

RE:Factorial Function Unlimited
-----------------------------------
this is one of the nice parts about haskell. In haskell you can simply:

factorial 0 = 0
factorial n = n*factorial(n-1)

Haskell by default will decide what type to use, and one of it's types is an abitrarily large integer. 


The use of BigInteger IMO is completely underused. ANY calculator app should use BigInteger as speed and memory usage aren't as important as accuracy.

-----------------------------------
TerranceN
Tue Oct 30, 2012 11:46 am

RE:Factorial Function Unlimited
-----------------------------------
Using lazy evaluation you can even create the infinite list of ALL factorial values:


factorial = 1:zipWith (*) factorial 

-----------------------------------
mirhagk
Tue Oct 30, 2012 11:54 am

RE:Factorial Function Unlimited
-----------------------------------
@OP if you think your program is neat, I would HIGHLY suggest you look into haskell. It's fun. 
http://learnyouahaskell.com/ Great place to learn.

-----------------------------------
randint
Sun Nov 18, 2012 11:38 am

Re: Factorial Function Unlimited
-----------------------------------
It is not like I do not understand recursion--I know that n! = n * (n - 1)! for all n > 0, I do not use it because the computational complexity is terrible. It is easy to code but takes an infinite amount of time, with great possibility of a StackOverflowError when the input is >= 2000 (?).

-----------------------------------
randint
Sun Nov 18, 2012 11:51 am

RE:Factorial Function Unlimited
-----------------------------------
By the way, mirhagk, 0! is 1 by definition.

-----------------------------------
md
Sun Nov 18, 2012 12:48 pm

RE:Factorial Function Unlimited
-----------------------------------
mirhagk, stop hounding people to try Haskell. Post something about it in the general forums and present some reasons for trying it.
