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

namespace path {::tcl::mathfunc ::tcl::mathop ::tcl::unsupported}
proc exteuclid {a b {x 0} {lx 1} {y 1} {ly 0}} {
    if {$b == 0} {
        list $lx $ly $a
    } else {
        set q [/ $a $b]
        tailcall exteuclid $b [% $a $b] \
            [- $lx [* $q $x]] $x [- $ly [* $q $y]] $y
    }
}
proc demo {a b} {
    puts [linsert [linsert [exteuclid $a $b] 2 * $b ==] 1 * $a +]
}
demo 100 240