fibonacci

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package fibonacci allows you to calculate which fibonacci number would be at a given index. Imagine the fibonacci sequence is represented in the form of a slice of ints, similar to the below example.

Fibonacci Sequence
[]int{0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233...}
Example
package main

import (
	"fmt"

	"github.com/eng618/go-eng/algo/fibonacci"
)

func main() {
	// Fibonacci example
	fibO := fibonacci.Dynamic()
	fmt.Println(fibO(10))

	// FibonacciBU example
	fmt.Println(fibonacci.BottomUp(10))

	// Fib example
	fmt.Println(fibonacci.Basic(10))

}
Output:

55
55
55

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Basic

func Basic(n int) int

Basic function is simple implementation.

func BottomUp

func BottomUp(n int) int

BottomUp is a bottom up approach to finding the number.

func Dynamic

func Dynamic() func(n int) int

Dynamic utilizes memoization and dynamic programming principle, to calculate the the fibonacci number for a given index.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL