+ import std.math; import std.typecons; - import std.math; /* Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in - the last couple centuries. However, what people don't know is Tribonacci sequence. ? ---- + the last couple centuries. However, what people don't know is Tribonacci sequence. - Tribonacci sequence is defined by the recurrence: ? ---- + Tribonacci sequence is defined by the recurrence: - tri(1) = 3 ? ---- + tri(1) = 3 - tri(n) = 1 + n / 2, if n is even. ? ---- + tri(n) = 1 + n / 2, if n is even. - tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd. ? ---- + tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd. - For example: ? ---- + For example: - tri(2) = 1 + (2 / 2) = 2 ? ---- + tri(2) = 1 + (2 / 2) = 2 - tri(4) = 3 ? ---- + tri(4) = 3 - tri(3) = tri(2) + tri(1) + tri(4) ? ---- + tri(3) = tri(2) + tri(1) + tri(4) - = 2 + 3 + 3 = 8 ? ---- + = 2 + 3 + 3 = 8 - You are given a non-negative integer number n, you have to a return an array of the ? ---- + You are given a non-negative integer number n, you have to a return an array of the - first n + 1 numbers of the Tribonacci sequence. ? ---- + first n + 1 numbers of the Tribonacci sequence. - Examples: ? ---- + Examples: - >>> tri(3L) ? ---- + >>> tri(3L) - [1L, 3L, 2L, 8L] ? ---- + [1L, 3L, 2L, 8L] - */ long[] tri(long n)