Yes, I’m indeed asking a super easy but meaningful question. I’m wondering a really elegant (without sacrificing algorithm complexity) answer.
But here I’m asking for the most elegant way
There are some answers to this question:
Pascal’s Triangle 1
Pascal’s Triangle 2
and also fssnip. net / 2b (remove the blank)
Pascal’s Triangle 3
I’m looking for elegance
Looks as if Haskell have a pretty good solution, still doesn’t how to handle it in F#
This is elegant, isn’t it? Short and fast. What else do you need?
let rec PascalsTriangle = seq {
yield [1];
for aLine in PascalsTriangle ->
List.append (1::Seq.toList (Seq.map (fun (x,y) -> x+y) (Seq.pairwise aLine))) ([1])
}
printfn"%A" (PascalsTriangle |> Seq.take 10 |> Seq.toList)
???