Created
December 13, 2018 18:19
-
-
Save UlisseMini/2da8056bc946d5c1ea63150391aa97ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 <=)