woonie

extended euclid iter2

Sep 13th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.43 KB | None | 0 0
  1. ;extended euclid algorithm
  2.  
  3. (define (solve-ax+by=1 a b)
  4.   (euclid1 a b (floor (/ a b)) (modulo a b) 1 0 0 1))
  5. (define (euclid1 dividend divisor quot rem x y x1 y1)
  6.   ;; What is the invalid case?
  7.   (cond ((not (= (gcd dividend divisor) 1)) (display "no solution orz"))
  8.         ((= rem 0) (cons x1 y1))
  9.         (else (euclid1 divisor rem (floor (/ divisor rem)) (modulo divisor rem) x1 y1 (- x (* quot x1)) (- y (* quot y1))))))
Advertisement
Add Comment
Please, Sign In to add comment