Pi: Difference between revisions

504 bytes added ,  2 years ago
→‎{{header|F_Sharp|F#}}: Haskell can probably do this as an unfold, it has not so I shall in F#
(c++ entry)
(→‎{{header|F_Sharp|F#}}: Haskell can probably do this as an unfold, it has not so I shall in F#)
Line 2,137:
 
=={{header|F_Sharp|F#}}==
===Translation of Haskell===
{{trans|Haskell}}
<lang fsharp>let rec g q r t k n l = seq {
Line 2,160 ⟶ 2,161:
320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219
6086403441815981362977477130996051870721134999999</pre>
===As an Unfold===
Haskell can probably do this as an unfold, it has not so I shall in F#
<lang fsharp>
// Generate Pi as above using unfold. Nigel Galloway: March 15th., 2022
let Pi()=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
Pi()|>Seq.take 767|>Seq.iter(printf "%d")
</lang>
 
=={{header|Factor}}==
2,171

edits