From f41a9a63599d92cab993de4d5d676351069957c3 Mon Sep 17 00:00:00 2001 From: Melvin Date: Thu, 8 Jan 2015 01:08:29 +0530 Subject: [PATCH 1/3] Added factorial example to examples --- examples/fact.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 examples/fact.jl diff --git a/examples/fact.jl b/examples/fact.jl new file mode 100644 index 0000000000000..49493d365422c --- /dev/null +++ b/examples/fact.jl @@ -0,0 +1,14 @@ +#Tail Recursion Factorial using Julia + +function fact(acc::BigInt,n) + if n == 0 + acc + else + fact(acc* n,n-1) + end +end + +function factorial(n) + fact(BigInt(1),n) +end + From a3a5243c3d4c0b4057dd7fcdc229d9df2e8967b0 Mon Sep 17 00:00:00 2001 From: Melvin Date: Thu, 8 Jan 2015 01:24:56 +0530 Subject: [PATCH 2/3] removed spaces to build. Added Factorial to examples --- examples/fact.jl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/fact.jl b/examples/fact.jl index 49493d365422c..14b935becf4fc 100644 --- a/examples/fact.jl +++ b/examples/fact.jl @@ -1,14 +1,13 @@ #Tail Recursion Factorial using Julia -function fact(acc::BigInt,n) - if n == 0 - acc - else - fact(acc* n,n-1) - end +function fact(acc::BigInt,n) + if n == 0 + acc + else + fact(acc* n,n-1) + end end function factorial(n) - fact(BigInt(1),n) -end - + fact(BigInt(1),n) +end \ No newline at end of file From e9758295627923583e8838fe37de9838e9f8b51f Mon Sep 17 00:00:00 2001 From: Melvin Date: Thu, 8 Jan 2015 03:16:37 +0530 Subject: [PATCH 3/3] changed function name --- examples/fact.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/fact.jl b/examples/fact.jl index 14b935becf4fc..aac66cb20b0e4 100644 --- a/examples/fact.jl +++ b/examples/fact.jl @@ -8,6 +8,6 @@ function fact(acc::BigInt,n) end end -function factorial(n) +function factorialexample(n) fact(BigInt(1),n) -end \ No newline at end of file +end