Sylvester's sequence: Difference between revisions
Content deleted Content added
Added PL/M |
Realize in F# |
||
Line 110:
</pre>
==={{header|F_Sharp|F#}}==
<lang fsharp>
// Sylvester's sequence: Nigel Galloway. June 7th., 2021
let S10=Seq.unfold(fun(n,g)->printfn "*%A %A" n g; Some(n,(n*g+1I,n*g) ) )(2I,1I)|>Seq.take 10|>List.ofSeq
S10|>List.iteri(fun n g->printfn "%2d -> %A" (n+1) g)
let n,g=S10|>List.fold(fun(n,g) i->(n*i+g,g*i))(0I,1I) in printfn "\nThe sum of the reciprocals of S10 is \n%A/\n%A" n g
</lang>
{{out}}
<pre>
1 -> 2
2 -> 3
3 -> 7
4 -> 43
5 -> 1807
6 -> 3263443
7 -> 10650056950807
8 -> 113423713055421844361000443
9 -> 12864938683278671740537145998360961546653259485195807
10 -> 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443
The sum of the reciprocals of S10 is
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806
</pre>
=={{header|Factor}}==
Note that if the previous element of the sequence is x, the next element is x<sup>2</sup>-x+1.
|