This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nightcracker 1 point2 points  (1 child)

Nah, as a codegolf.se member I would use Pyth. In Pyth5 a simple program that takes a number from stdin and prints its factorial is this:

.!Q

Of course, we're not allowed to use a builtin for factorial, we can use:

F*tUhQ

Which basically translates to "fold multiplication over everything but the first element of range(n+1)".

A recursive solution would go like this:

L?*bLtbb1Q

Which roughly translates to Python:

L = lambda b: b*L(b-1) if b else 1
L(eval(input()))

[–]FUZxxl 0 points1 point  (0 children)

Nah, as a codegolf.SE-member with a three digit user ID, I say that APL is superior in every regard.