SHARE
TWEET

Untitled

a guest Jun 24th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "os"
  5.     "fmt"
  6.     "strconv"
  7. )
  8.  
  9. func main() {
  10.     input := os.Args[1]
  11.     n, _ := strconv.Atoi(input)
  12.     result := fibonacciDP(n)
  13.     fmt.Println(result)
  14. }
  15.  
  16. func fibonacci(n int) int {
  17.     if n <= 2 {
  18.         return 1
  19.     }
  20.     return fibonacci(n-1) + fibonacci(n-2)
  21. }
  22.  
  23. func fibonacciDP(n int) int {
  24.     tmp, n1, n2 := 1, 1, 1
  25.     for i := 1; i < n; i++ {
  26.         tmp = n1 + n2
  27.         n1 = n2
  28.         n2 = tmp
  29.     }
  30.     return tmp
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top