Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.9", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"},
{:benchee, "~> 1.1"}
])
The Fibonacci sequence is a series of the following numbers.
flowchart LR
a[0] --> b[1] --> c[1] --> d[2] --> e[3] --> f[5] --> g[8] --> h[13] --> i[21] --> k[34] --> ...
It's created by taking the sum of the previous to numbers to get the next number.
So
Implement the Fibonacci.sequence/1
function below. Do not worry about performance for this solution.
defmodule Fibonacci do
@doc """
Generate the fibonacci sequence of a given length.
## Examples
iex>
"""
def sequence(length) do
end
end
In the Elixir cell below, create a FastFib
module. The FastFib
module should be the most performant version of the Fibonacci Sequence that you can create.
defmodule FastFib do
def sequence(length) do
end
end
Use Benchee to benchmark the performance of FastFib.sequence/1
function. The student in the class with the fastest FastFib
time wins.
Benchee.run(
%{
fast_fib: fn n -> FastFib.sequence(n) end
},
inputs: %{
"1: small" => 10,
"2: medium" => 30
# Uncomment the following if your solution can handle it!
# Make sure to add a comma above.
# "3: large" => 100,
# "4: xl" => 1000,
# "6: 2xl" => 10000,
# "7: 3xl" => 100_000
},
memory_time: 2
)
DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.
Run git status
to ensure there are no undesirable changes.
Then run the following in your command line from the curriculum
folder to commit your progress.
$ git add .
$ git commit -m "finish Fibonacci Sequence exercise"
$ git push
We're proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.
We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.