write a function for sequence calculation
This commit is contained in:
parent
959357e1f9
commit
f5d0ff1e61
|
|
@ -24,6 +24,14 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func seq(x, xprev, a *big.Int) {
|
||||
tmp := new(big.Int)
|
||||
tmp.Mul(a, x)
|
||||
tmp.Add(tmp, xprev)
|
||||
xprev.Set(x)
|
||||
x.Set(tmp)
|
||||
}
|
||||
|
||||
func convergents(cmd *cobra.Command, args []string) {
|
||||
hprev := big.NewInt(0)
|
||||
kprev := big.NewInt(1)
|
||||
|
|
@ -44,32 +52,14 @@ func convergents(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
tmp := new(big.Int)
|
||||
tmp.Mul(a0, h)
|
||||
tmp.Add(tmp, hprev)
|
||||
hprev.Set(h)
|
||||
h.Set(tmp)
|
||||
|
||||
tmp.Mul(a0, k)
|
||||
tmp.Add(tmp, kprev)
|
||||
kprev.Set(k)
|
||||
k.Set(tmp)
|
||||
|
||||
seq(h, hprev, a0)
|
||||
seq(k, kprev, a0)
|
||||
fmt.Println(h, k)
|
||||
|
||||
for i := 0; true; i = (i + 1) % len(denoms) {
|
||||
a := &denoms[i]
|
||||
|
||||
tmp.Mul(a, h)
|
||||
tmp.Add(tmp, hprev)
|
||||
hprev.Set(h)
|
||||
h.Set(tmp)
|
||||
|
||||
tmp.Mul(a, k)
|
||||
tmp.Add(tmp, kprev)
|
||||
kprev.Set(k)
|
||||
k.Set(tmp)
|
||||
|
||||
seq(h, hprev, a)
|
||||
seq(k, kprev, a)
|
||||
fmt.Println(h, k)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue