From c537b3dc714cf08d3f4505f887698a1ea74bd2f8 Mon Sep 17 00:00:00 2001 From: filifa Date: Mon, 11 Aug 2025 23:36:54 -0400 Subject: [PATCH] break out bezout computations to separate function --- cmd/gcd.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/cmd/gcd.go b/cmd/gcd.go index 48e875f..854007b 100644 --- a/cmd/gcd.go +++ b/cmd/gcd.go @@ -26,6 +26,16 @@ import ( var extended bool +func computeBezouts(bezouts []big.Int, x, y *big.Int) { + for i, c := range bezouts { + if i == len(bezouts)-1 { + bezouts[i].Set(y) + } else { + bezouts[i].Mul(&c, x) + } + } +} + func gcd(cmd *cobra.Command, args []string) { x := new(big.Int) y := new(big.Int) @@ -42,17 +52,8 @@ func gcd(cmd *cobra.Command, args []string) { z.GCD(x, y, z, w) - if !extended { - continue - } - - for j, c := range bezouts { - if j == i { - bezouts[j].Set(y) - } else { - bezouts[j].Mul(&c, x) - } - + if extended { + computeBezouts(bezouts[:i+1], x, y) } }