Skip to content

Instantly share code, notes, and snippets.

@UlisseMini
Created December 13, 2018 18:19
Show Gist options
  • Save UlisseMini/2da8056bc946d5c1ea63150391aa97ae to your computer and use it in GitHub Desktop.
Save UlisseMini/2da8056bc946d5c1ea63150391aa97ae to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/big"
"os"
"strconv"
)
func main() {
if len(os.Args) != 2 {
fmt.Printf("Usage: %s <number>\n", os.Args[0])
os.Exit(1)
}
num, err := strconv.ParseUint(os.Args[1], 0, 64)
if err != nil {
fmt.Printf("%q is not a valid uint64\n", os.Args[1])
os.Exit(1)
}
p := big.NewInt(0) // p = prev c
c := big.NewInt(1) // c = prev term
t := big.NewInt(0) // t = term
for i := uint64(1); i <= num; i++ {
t = p.Add(p, c)
// reset state
p = c
c = t
}
fmt.Println(t)
}
@UlisseMini
Copy link
Author

UlisseMini commented Dec 13, 2018

You can ignore everything before line 21, its just parsing the command line arguments.
also i made the loop start at one, its still looping the same amount though (notice the <=)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment