Skip to content

Commit

Permalink
fib readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bddicken committed Dec 9, 2024
1 parent 4921d3b commit 799ca0e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,10 @@ You are also welcome to add new top-level benchmarks dirs

Each benchmark exists in a subdirectory with the corresponding name.

## [loops](./loops/README.md)
### [loops](./loops/README.md)

### [fibonacci](./fibonacci/README.md)

## fibonacci

This program computes the sum of the first N fibonacci numbers.
Each fibonacci number is computed using a naive recursive solution.
Submissions using faster tail-recursion or iterative solutions will not not be accepted.
Emphasizes function call overhead, stack pushing / popping, and recursion.

## levenshtein

Expand Down
30 changes: 30 additions & 0 deletions fibonacci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Fibonacci

This program computes the sum of the first N fibonacci numbers.
Each fibonacci number is computed using a naive recursive solution.
Submissions using faster tail-recursion or iterative solutions will not not be accepted.
Emphasizes function call overhead, stack pushing / popping, and recursion.

Below is the reference C program.
All languages must do the same array work and computations outlined here.

```C
#include "stdio.h"
#include "stdlib.h"
#include "stdint.h"
// ALL IMPLEMENTAITONS MUST...
int32_t fibonacci(int32_t n) { // Have a function that recursively compute a fibonacci number with this naive algorithm
if (n == 0) return 0; // Base case for input 0
if (n == 1) return 1; // Base case for input 1
return fibonacci(n-1) + fibonacci(n-2); // Must make two recursive calls for each non-base invocation
} // No result caching, conversion to tail recursion, or iterative solutions.

int main (int argc, char** argv) {
int32_t u = atoi(argv[1]); // Get exactly one numberic value from the command line
int32_t r = 0; // Create variable to store sum
for (int32_t i = 1; i < u; i++) { // Loop 1...u times
r += fibonacci(i); // Sum all fibonacci numbers 1...u
}
printf("%d\n", r); // Print out the single, numeric sum
}
```

0 comments on commit 799ca0e

Please sign in to comment.