Tribonacci Sequence
Description:
Well met with Fibonacci bigger brother, AKA Tribonacci.
As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't get to hear non-native Italian speakers trying to pronounce it :(
So, if we are to start our Tribonacci sequence with [1, 1, 1]
as a starting input (AKA signature), we have this sequence:
[1, 1 ,1, 3, 5, 9, 17, 31, ...]
But what if we started with [0, 0, 1]
as a signature? As starting with [0, 1]
instead of [1, 1]
basically shifts the common Fibonacci sequence by once place, you may be tempted to think that we would get the same sequence shifted by 2 places, but that is not the case and we would get:
[0, 0, 1, 1, 2, 4, 7, 13, 24, ...]
Well, you may have guessed it by now, but to be clear: you need to create a fibonacci function that given a signature array/list, returns the first n elements - signature included of the so seeded sequence.
Signature will always contain 3 numbers; n will always be a non-negative number; if n == 0
, then return an empty array (except in C return NULL) and be ready for anything else which is not clearly specified ;)
If you enjoyed this kata more advanced and generalized version of it can be found in the Xbonacci kata
[Personal thanks to Professor Jim Fowler on Coursera for his awesome classes that I really recommend to any math enthusiast and for showing me this mathematical curiosity too with his usual contagious passion :)]
Similar Kata:
Stats:
Created | Jun 2, 2015 |
Published | Jun 2, 2015 |
Warriors Trained | 346794 |
Total Skips | 63592 |
Total Code Submissions | 631136 |
Total Times Completed | 160595 |
Python Completions | 61800 |
JavaScript Completions | 47565 |
Ruby Completions | 4759 |
Haskell Completions | 1919 |
Java Completions | 14288 |
CoffeeScript Completions | 94 |
C# Completions | 8515 |
Elixir Completions | 449 |
F# Completions | 180 |
OCaml Completions | 122 |
Crystal Completions | 42 |
PHP Completions | 3171 |
Swift Completions | 1114 |
C++ Completions | 8156 |
Scala Completions | 345 |
Kotlin Completions | 845 |
C Completions | 2440 |
Rust Completions | 1757 |
Reason Completions | 11 |
Elm Completions | 47 |
Clojure Completions | 203 |
Go Completions | 1848 |
TypeScript Completions | 2591 |
Dart Completions | 852 |
Factor Completions | 20 |
Groovy Completions | 46 |
Julia Completions | 110 |
R Completions | 129 |
Racket Completions | 54 |
COBOL Completions | 11 |
D Completions | 9 |
Total Stars | 3360 |
% of votes with a positive feedback rating | 89% of 14844 |
Total "Very Satisfied" Votes | 12032 |
Total "Somewhat Satisfied" Votes | 2483 |
Total "Not Satisfied" Votes | 329 |