Tracks
/
Rust
Rust
/
Exercises
/
A Short Fibonacci Sequence
A Short Fibonacci Sequence

A Short Fibonacci Sequence

Learning Exercise

Introduction

Rust provides a macro vec![] to help you create Vectors. This comes in quite handy when you need to initialize lists.

Instructions

You are going to initialize empty buffers and list the first five numbers, or elements, of the Fibonacci sequence.

The Fibonacci sequence is a set of numbers where the next element is the sum of the prior two. We start the sequence at one. So the first two elements are 1 and 1.

1. Create a buffer of count zeroes.

Create a function that creates a buffer of count zeroes.

let my_buffer = create_buffer(5);
// [0, 0, 0, 0, 0]

2. List the first five elements of the Fibonacci sequence

Create a function that returns the first five numbers of the Fibonacci sequence. Its first five elements are 1, 1, 2, 3, 5

let first_five = fibonacci();
// [1, 1, 2, 3, 5]
Edit via GitHub The link opens in a new window or tab
Rust Exercism

Ready to start A Short Fibonacci Sequence?

Sign up to Exercism to learn and master Rust with 98 exercises, and real human mentoring, all for free.