github.com/ks888/tgo@v0.0.0-20190130135156-80bf89407292/_examples/fib.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strconv"
     7  
     8  	"github.com/ks888/tgo/lib/tracer"
     9  )
    10  
    11  func fib(n int) int {
    12  	if n == 0 || n == 1 {
    13  		return n
    14  	}
    15  	return fib(n-1) + fib(n-2)
    16  }
    17  
    18  func main() {
    19  	tracer.Start()
    20  
    21  	var n int64
    22  	if len(os.Args) > 1 {
    23  		n, _ = strconv.ParseInt(os.Args[1], 10, 64)
    24  	}
    25  	val := fib(int(n))
    26  	fmt.Println(val)
    27  
    28  	tracer.Stop()
    29  }