Factorial competition

For anyone that’s bored, what’s the most concise code you can come up with to print out factorial(n) for n in the range 1-11 , in your language of choice?

  • If there are any bored Perl programmers about I’m expecting Perl to win … here’s my best attempt in “C” … be interesting to see how different languages compare [?!]
#include <stdio.h>

long factorial(long n) { return n==1?n:n*factorial(n-1); }

int main() { for(int i=1;i<12;i++) printf("Factorial %d = %ld\n",i,factorial(i)); }

Ok, here’s the Python submission;

def factorial(n):return reduce(lambda x,y:x*y,[1]+range(1,n+1))

Fractionally longer and IMHO a lot less readable [?]

Anybody for LISP ?

(defun factorial (n)  (if (= n 0) 1 (* n (factorial (- n 1))) ) )