6 kyu

Tribonacci Sequence

62,481 of 162,146GiacomoSorbi

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 :)]

Number Theory
Arrays
Lists
Fundamentals

Stats:

CreatedJun 2, 2015
PublishedJun 2, 2015
Warriors Trained349437
Total Skips63880
Total Code Submissions635226
Total Times Completed162146
Python Completions62481
JavaScript Completions47985
Ruby Completions4765
Haskell Completions1932
Java Completions14403
CoffeeScript Completions94
C# Completions8584
Elixir Completions451
F# Completions181
OCaml Completions122
Crystal Completions42
PHP Completions3193
Swift Completions1121
C++ Completions8248
Scala Completions348
Kotlin Completions855
C Completions2462
Rust Completions1772
Reason Completions11
Elm Completions47
Clojure Completions204
Go Completions1895
TypeScript Completions2636
Dart Completions861
Factor Completions20
Groovy Completions47
Julia Completions110
R Completions131
Racket Completions54
COBOL Completions11
D Completions9
Total Stars3388
% of votes with a positive feedback rating89% of 14903
Total "Very Satisfied" Votes12076
Total "Somewhat Satisfied" Votes2497
Total "Not Satisfied" Votes330
Ad
Contributors
  • GiacomoSorbi Avatar
  • jhoffner Avatar
  • hbakhtiyor Avatar
  • spencerwi Avatar
  • Bodigrim Avatar
  • Unnamed Avatar
  • baliuk91@gmail.com Avatar
  • anter69 Avatar
  • nbeck Avatar
  • Chrono79 Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • DonVito1982 Avatar
  • ryancastle Avatar
  • wneumann Avatar
  • Voile Avatar
  • kzm Avatar
  • rowcased Avatar
  • FArekkusu Avatar
  • monadius Avatar
  • della-90 Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • cliffstamp Avatar
  • qwertyu123 Avatar
  • user8436785 Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
  • yLaWy Avatar
  • KayleighWasTaken Avatar
Ad