fibgo

package module
v0.0.0-...-0a7d170 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2017 License: MIT Imports: 3 Imported by: 0

README

Build Status Coverage Status

Fibonacci

Provide functionality for fibonacci related operation

Installation

$ go get github.com/uudashr/fibgo

Usage

Get fibonacci number of N

import (
  "fmt"
  fib "github.com/uudashr/fibgo"
)

func ExampleN() {
	fmt.Println(fib.N(0))
	fmt.Println(fib.N(6))
	fmt.Println(fib.N(9))
	// Output:
	// 0
	// 8
	// 34
}

Or get sequence with length 10

import (
  "fmt"
  fib "github.com/uudashr/fibgo"
)

func ExampleSeq() {
	fmt.Println(fib.Seq(10))
	// Output: [0 1 1 2 3 5 8 13 21 34]
}

Or create HTTP Service

package main

import (
	"log"
	"net/http"

	fib "github.com/uudashr/fibgo"
)

func main() {
	handler := fib.NewHTTPHandler()
	log.Println("Listening on port", 8080, "...")
	err := http.ListenAndServe(":8080", handler)
	log.Println("Stopped err:", err)
}

Running the fibgo service

Fibgo provide the http service for fibonacci numbers.

To run the service

$ fibgo-server --port 8080

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func N

func N(n int) int

N return fibonacci number on N position N should start from 0, otherwise panic will raised

Example
package main

import (
	"fmt"

	fib "github.com/uudashr/fibgo"
)

func main() {
	fmt.Println(fib.N(0))
	fmt.Println(fib.N(6))
	fmt.Println(fib.N(9))
}
Output:

0
8
34

func NewHTTPHandler

func NewHTTPHandler() http.Handler

NewHTTPHandler create new http.Handler

func Seq

func Seq(length int) []int

Seq will generate the fibonacci sequence

Example
package main

import (
	"fmt"

	fib "github.com/uudashr/fibgo"
)

func main() {
	fmt.Println(fib.Seq(10))
}
Output:

[0 1 1 2 3 5 8 13 21 34]

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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