factorial

C++ algorithm for N! orderings

I have a list of N items and I am wondering how I can loop through the list to get every combination. There are no doubles, so I need to get all N! orderings. Extra memory is no problem, I'm trying to think of the simplest algorithm but I'm having trouble. ...

Complexity Of Recursive Factorial Program

What's the complexity of a recursive program to find factorial of a number n? My hunch is that it might be O(n) ...

How to find a factorial?

How can I write a program to find the factorial of any number? ...

Ruby factorial function

I'm going crazy: Where is the Ruby function for factorial? No, I don't need tutorial implementations, I just want the function from the library. It's not in Math! I'm starting to doubt, is it a standard library function? ...

Factorial in Prolog and C++

I would like to work out a number's factorial. My factorial rule is in a Prolog file and I am connecting it to a C++ file. Can someone please tell me what is wrong with my interfacing C++ to Prolog? my factorial.pl file: factorial( 1, 1 ):- !. factorial( X, Fac ):- X > 1, Y is X - 1, factorial( Y, New_Fac ), Fac i...

Basic recursive method - factorial

I am practicing recursion and I can't see why this method does not seem to work. Any ideas? public void fact() { fact(5); } public int fact(int n) { if(n == 1){ return 1; } return n * (fact(n-1)); } } Thanks ...

Is there is some mathematical "optimum" base that would speed up factorial calculation?

Is there is some mathematical "optimum" base that would speed up factorial calculation? Background: Just for fun, I'm implementing my own bignum library. (-: Is this my first mistake? :-). I'm experimenting with various bases used in the internal representation and regression testing by printing out exact values (in decimal) for n facto...

How to calculate the inverse factorial of a real number?

Is there some way to calculate the inverse factorials of real numbers? For example - 1.5 ! = 1.32934039 Is there some way to obtain 1.5 back if I have the value 1.32934039? I am trying http://www.wolframalpha.com/input/?i=Gamma^(-1)[1.32934039] but that is a fail. ...

Why won't `let` work for naming internal recursive procedures?

Consider the following implementation of a function to compute factorial: [1] (define fac-tail (lambda (n) (define fac-tail-helper (lambda (n ac) (if (= 0 n) ac (fac-tail-helper (- n 1) (* n ac))))) (fac-tail-helper n 1))) I attempted to rewrite using let for the inner define: (define f...

Fastest factorial implementation with 64-bit result in assembly.

This is not homework, just something I though of. So, straight computing factorial is not exactly fast; memoization can help, but if the result is to fit into 32 or 64 bits, then the factorial only can work for inputs 0 through 12 and 20 respectively. So ... we might as well use a lookup table: n n! 0 1 1 1 2 2 ...

write a c program/ factorial of N using do while

it factors a # 25=5 ...

Factorial -C (Linux)

Please suggest me a more efficient alternative to go about this Program #include <stdio.h> int main(void) { int k, i, t; int arr[100]; //Declaring an array printf("Enter a positive integer: "); scanf("%d", &k); for (i = 0; i < k; i++) { //printf("enter a value %d : ", i); scanf("%d", &arr[i]); ...

Regexercise: factorials

This is an experimental new feature for StackOverlow: exercising your regex muscles by solving various classical problems. There is no one right answer, and in fact we should collect as many right answers as possible, as long as they offer educational value. All flavors accepted, but please document it clearly. As much as practical, p...

Permutation for numbers in C

Hi programming masses, I'm trying to write a C function to list all permutations of a set of numbers, in groups of five, including repeat numbers: 15-11-49-43-5 2-30-34-6-11 So it's easy enough to write a function to grab all permutations of a number set and throw them out, but mapped to a certain group size, i'm somewhat stuck.. T...

Howto compute the factorial of x

how to get the value of an integer x, indicated by x!, it is the product of the numbers 1 to x. Example: 5! 1x2x3x4x5 = 120. int a , b = 1, c = 1, d = 1; printf("geheel getal x = "); scanf("%d", &a); printf("%d! = ", a); for(b = 1; b <= a; b++) { printf("%d x ", c); c++; d = d*a; } printf(" = %d", d); ...

Java: Simple recursion function returns only 1

This is oddly my first Java application, I was wanting to implement an arbitrary precision factorial function, I did the recursive one fine but my iterative one simply outputs "1" and nothing else.. It is so late for me I can not spot why, I am not sure where I went wrong, is there something obvious here? public static BigInteger ifact(...

Need to generate every unique combination of an array of files recursively

I've researched and found LOTS of similar requests, but nothing was quite what I needed. Here is my problem. I'm working in C#, and I have a FileInfo[] array with an unknown number of elements in it. FileInfo[] files = new FileInfo[] { new FileInfo(@"C:\a.jpg"), new FileInfo(@"C:\b.jpg"), new FileInfo(@"C:\c.jpg"), new...

C#: Code to fit LOTS of files onto a DVD as efficiently as possible

I need to write an application that will take a list of files (some large, some small) and fit them onto DVDs (or CDs, or whatever) as efficiently as possible. The whole point of this application is to use up as much of the 1st disc before moving onto the 2nd disc, filling the 2nd disc up as much as possible before moving onto the 3rd d...

factorial method doesn't work well!

Hi this is a factorial method but it prints 0 in the console please help me thanks public class Demo { public static void main(String[] args) { Demo obj = new Demo(); System.out.println(obj.factorial(500)); } public int factorial(int n) { int fact = 1; for (int i = 2; i <= n; i++) { ...

Problem with Recursion

Hello, I am running into a little pickle. For class I have an assignment (below), I came up with a solution but I keep getting an error, that says; "'factorial' : recursive on all control paths, function will cause runtime stack overflow;" If someone could help me, I've been working on this for about an hour and I'm stumped! Assi...