Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Sylvesters-sequence/Wren/sylvesters-sequence.wren
Normal file
20
Task/Sylvesters-sequence/Wren/sylvesters-sequence.wren
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import "/big" for BigInt, BigRat
|
||||
|
||||
var sylvester = [BigInt.two]
|
||||
var prod = BigInt.two
|
||||
var count = 1
|
||||
while (true) {
|
||||
var next = prod + 1
|
||||
sylvester.add(next)
|
||||
count = count + 1
|
||||
if (count == 10) break
|
||||
prod = prod * next
|
||||
}
|
||||
System.print("The first 10 terms in the Sylvester sequence are:")
|
||||
System.print(sylvester.join("\n"))
|
||||
|
||||
var sumRecip = sylvester.reduce(BigRat.zero) { |acc, s| acc + BigRat.new(1, s) }
|
||||
System.print("\nThe sum of their reciprocals as a rational number is:")
|
||||
System.print (sumRecip)
|
||||
System.print("\nThe sum of their reciprocals as a decimal number (to 211 places) is:")
|
||||
System.print(sumRecip.toDecimal(211))
|
||||
Loading…
Add table
Add a link
Reference in a new issue