use uint64 and panic on false numbers
- break piont at
This commit is contained in:
parent
7de645a7af
commit
0e29275c30
@ -13,10 +13,10 @@ var usage string = "usage: " + os.Args[0] + " <number of fibs>"
|
||||
// a function that returns an int.
|
||||
// from cpython/Doc/build/html/library/functools.html
|
||||
// [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]
|
||||
func fibonacci() func() int {
|
||||
cur_fib := 0
|
||||
nxt_fib := 0
|
||||
return func() int {
|
||||
func fibonacci() func() uint64 {
|
||||
cur_fib := uint64(0)
|
||||
nxt_fib := cur_fib
|
||||
return func() uint64 {
|
||||
if nxt_fib == 0 {
|
||||
nxt_fib = 1
|
||||
return 0
|
||||
@ -24,6 +24,9 @@ func fibonacci() func() int {
|
||||
tmp := cur_fib
|
||||
cur_fib = nxt_fib
|
||||
nxt_fib += tmp
|
||||
if nxt_fib < cur_fib {
|
||||
panic("overfull!!")
|
||||
}
|
||||
return cur_fib
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user