Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,14 @@
defmodule Factorial do
# Simple recursive function
def fac(0), do: 1
def fac(n) when n > 0, do: n * fac(n - 1)
# Tail recursive function
def fac_tail(n), do: fac_tail(n, 1)
def fac_tail(0, acc), do: acc
def fac_tail(n, acc) when n > 0, do: fac_tail(n - 1, acc * n)
# Using Enumeration features
def fac_reduce(0), do: 0
def fac_reduce(n) when n > 0, do: Enum.reduce(1..n, 1, &*/2)
end