<NME> factorial.fsx
<BEF> ADDFILE
<MSG> Merge pull request #69 from jasondown/factorial_fsharp

Added recursive and fold implementations of factorial in F#.
<DFF> @@ -0,0 +1,20 @@
+// Simple recursive solution with pattern matching.
+let factorial n =
+    let rec factorial' n acc =
+        match n with
+        | 0 -> acc
+        | _ -> factorial' (n - 1) (acc * n)
+    factorial' n 1
+
+// Another solution using List.fold
+let factorial2 n = 
+    [1..n] |> List.fold (*) 1
+
+// test
+// prints: 120
+printfn "%i" (factorial 5)
+printfn "%i" (factorial2 5)
+
+// prints: 1 1 2 6 24 120 720 5040 40320 362880 3628800
+[0..10] |> List.map factorial |> List.iter (printf "%i ")
+[0..10] |> List.map factorial2 |> List.iter (printf "%i ")
\ No newline at end of file

{'addition_count': 20, 'commit_subject': 'Merge pull request #69 from jasondown/factorial_fsharp', 'deletion_count': 0, 'file_extension': '.fsx', 'lang': 'fsx', 'license': 'mit', 'repo_name': 'mre/the-coding-interview'}