Created
October 31, 2012 23:56
-
-
Save NeilRobbins/3990746 to your computer and use it in GitHub Desktop.
Pascals Triangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Program | |
open System | |
let rec factor (n : int64) = | |
match n with | |
| 0L -> 1L | |
| _ -> n * (factor (n - 1L)) | |
let rec combinations r n = | |
match r with | |
| 0L -> 1L | |
| _ when r = n -> 1L | |
| _ -> (factor n)/((factor(n - r)) * (factor(r))) | |
let sizeOfTriangle = 15L | |
Console.Write("\t// ") | |
do | |
seq {0L .. sizeOfTriangle} | |
|> Seq.iter (fun n -> Console.Write("{0} \t", n)) | |
Console.WriteLine("") | |
do | |
seq {0L .. sizeOfTriangle} | |
|> Seq.iter (fun n -> Console.Write("{0}\t|| ", n) | |
seq {0L .. n} | |
|> Seq.map (fun r -> (r,n,combinations r n)) | |
|> Seq.iter (fun (r,n,c) -> Console.Write("{0}\t", c)) | |
Console.WriteLine("")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment