Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/Fusc-sequence/Swift/fusc-sequence.swift
Normal file
41
Task/Fusc-sequence/Swift/fusc-sequence.swift
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
struct FuscSeq: Sequence, IteratorProtocol {
|
||||
private var arr = [0, 1]
|
||||
private var i = 0
|
||||
|
||||
mutating func next() -> Int? {
|
||||
defer {
|
||||
i += 1
|
||||
}
|
||||
|
||||
guard i > 1 else {
|
||||
return arr[i]
|
||||
}
|
||||
|
||||
switch i & 1 {
|
||||
case 0:
|
||||
arr.append(arr[i / 2])
|
||||
case 1:
|
||||
arr.append(arr[(i - 1) / 2] + arr[(i + 1) / 2])
|
||||
case _:
|
||||
fatalError()
|
||||
}
|
||||
|
||||
return arr.last!
|
||||
}
|
||||
}
|
||||
|
||||
let first = FuscSeq().prefix(61)
|
||||
|
||||
print("First 61: \(Array(first))")
|
||||
|
||||
var max = -1
|
||||
|
||||
for (i, n) in FuscSeq().prefix(20_000_000).enumerated() {
|
||||
let f = String(n).count
|
||||
|
||||
if f > max {
|
||||
max = f
|
||||
|
||||
print("New max: \(i): \(n)")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue