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