Skip to content

Instantly share code, notes, and snippets.

@h0lyalg0rithm
Last active August 29, 2015 14:12
Show Gist options
  • Save h0lyalg0rithm/7eaeb6b26b243cc05268 to your computer and use it in GitHub Desktop.
Save h0lyalg0rithm/7eaeb6b26b243cc05268 to your computer and use it in GitHub Desktop.
defmodule Factorial do
def factorial(n) when n>1 do
n * factorial(n-1)
end
def factorial(n) when n <=1 do
1
end
end
function factorial(num){
if (num == 0) {
return 1;
}
var acc = num;
while (num-- > 2) {
acc *= num;
}
return acc;
}
def factorial(num)
unless num.nonzero?
1
else
num * factorial(num)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment