Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Sylvesters-sequence/Swift/sylvesters-sequence.swift
Normal file
21
Task/Sylvesters-sequence/Swift/sylvesters-sequence.swift
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import BigNumber
|
||||
|
||||
func sylvester(n: Int) -> BInt {
|
||||
var a = BInt(2)
|
||||
|
||||
for _ in 0..<n {
|
||||
a = a * a - a + 1
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
var sum = BDouble(0)
|
||||
|
||||
for n in 0..<10 {
|
||||
let syl = sylvester(n: n)
|
||||
sum += BDouble(1) / BDouble(syl)
|
||||
print(syl)
|
||||
}
|
||||
|
||||
print("Sum of the reciprocals of first ten in sequence: \(sum)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue