Posted to tcl by kbk at Wed Sep 17 20:39:49 GMT 2008view raw

  1. namespace path {::tcl::mathfunc ::tcl::mathop ::tcl::unsupported}
  2. proc exteuclid {a b {x 0} {lx 1} {y 1} {ly 0}} {
  3. if {$b == 0} {
  4. list $lx $ly $a
  5. } else {
  6. set q [/ $a $b]
  7. tailcall exteuclid $b [% $a $b] \
  8. [- $lx [* $q $x]] $x [- $ly [* $q $y]] $y
  9. }
  10. }
  11. proc demo {a b} {
  12. puts [linsert [linsert [exteuclid $a $b] 2 * $b ==] 1 * $a +]
  13. }
  14. demo 100 240