diff --git a/src/types-and-values/exercise.md b/src/types-and-values/exercise.md index 1512208b..f12aec7c 100644 --- a/src/types-and-values/exercise.md +++ b/src/types-and-values/exercise.md @@ -4,16 +4,15 @@ minutes: 15 # Exercise: Fibonacci -The first and second Fibonacci numbers are both `1`. For n>2, the n'th Fibonacci -number is calculated recursively as the sum of the n-1'th and n-2'th Fibonacci -numbers. +The Fibonacci sequence begins with `[0,1]`. For n>1, the n'th Fibonacci number +is calculated recursively as the sum of the n-1'th and n-2'th Fibonacci numbers. Write a function `fib(n)` that calculates the n'th Fibonacci number. When will this function panic? ```rust,editable,should_panic {{#include exercise.rs:fib}} - if n <= 2 { + if n < 2 { // The base case. todo!("Implement this") } else { diff --git a/src/types-and-values/exercise.rs b/src/types-and-values/exercise.rs index f09513f4..01a8ad4a 100644 --- a/src/types-and-values/exercise.rs +++ b/src/types-and-values/exercise.rs @@ -16,8 +16,8 @@ // ANCHOR: fib fn fib(n: u32) -> u32 { // ANCHOR_END: fib - if n <= 2 { - return 1; + if n < 2 { + return n; } else { return fib(n - 1) + fib(n - 2); }