Pi: Difference between revisions

Content added Content deleted
m (→‎Translation of Haskell: updated syntaxhighlight lang=, etc...)
m (→‎As an Unfold: updated syntaxhighlight lang=, etc...)
Line 2,160: Line 2,160:
===As an Unfold===
===As an Unfold===
Haskell can probably do this as an unfold, it has not so I shall in F#
Haskell can probably do this as an unfold, it has not so I shall in F#
<lang fsharp>
<syntaxhighlight lang=fsharp>
// Generate Pi as above using unfold. Nigel Galloway: March 15th., 2022
// Generate Pi as above using unfold. Nigel Galloway: March 15th., 2022
let π()=Seq.unfold(fun(q,r,t,k,n,l)->Some(if 4I*q+r-t < n*t then(Some(int n),((10I*q),(10I*(r-n*t)),t,k,((10I*(3I*q+r))/t-10I*n),l)) else (None,((q*k),((2I*q+r)*l),(t*l),(k+1I),((q*(7I*k+2I)+r*l)/(t*l)),(l+2I)))))(1I,0I,1I,1I,3I,3I)|>Seq.choose id
let π()=Seq.unfold(fun(q,r,t,k,n,l)->Some(if 4I*q+r-t < n*t then(Some(int n),((10I*q),(10I*(r-n*t)),t,k,((10I*(3I*q+r))/t-10I*n),l)) else (None,((q*k),((2I*q+r)*l),(t*l),(k+1I),((q*(7I*k+2I)+r*l)/(t*l)),(l+2I)))))(1I,0I,1I,1I,3I,3I)|>Seq.choose id
π()|>Seq.take 767|>Seq.iter(printf "%d")
π()|>Seq.take 767|>Seq.iter(printf "%d")
</syntaxhighlight>
</lang>


=={{header|Factor}}==
=={{header|Factor}}==