Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Lazy and infinite sequences / Exercises

The Tribonacci sequence

Problem

Using the sequence operator with a closure, build the Tribonacci sequence — like Fibonacci, but each number is the sum of the previous three, starting 1, 1, 1. Print its first eight numbers.

Example

The program prints:

(1 1 1 3 5 9 17 31)

Solution

See the solution

Course navigation

Solution: Powers of three   |   Solution: The Tribonacci sequence