Skip to content

Instantly share code, notes, and snippets.

@alexreg
Created July 4, 2020 14:40
Show Gist options
  • Select an option

  • Save alexreg/3702f72ca36291aa99738440334d949e to your computer and use it in GitHub Desktop.

Select an option

Save alexreg/3702f72ca36291aa99738440334d949e to your computer and use it in GitHub Desktop.
func tribonacci(_ signature: [Int], _ n: Int) -> [Int] {
let signature = (signature[0], signature[1], signature[2])
return Array(sequence(first: signature, next: { (a, b, c) in
(b, c, a + b + c)
}).map { $0.0 }.prefix(n))
}
print(tribonacci([1, 1, 1], 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment