Guest User

Untitled

a guest
Jan 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.56 KB | None | 0 0
  1. #lang racket
  2. (require test-engine/racket-tests)
  3.  
  4. (define (zminus x y) (+ x (- y)))
  5.  
  6. (define (zmul x y)
  7.  (zmulh x y x))
  8.  
  9. ;; (zmulh x y z) returns (y-1) * z + x, for any non-negative number y
  10. (define (zmulh x y z)
  11.   (if (< y 2)
  12.    (if
  13.     (= y 0)
  14.     0
  15.     x)
  16.    (zmulh (+ x z) (zminus y 1) z)))
  17.  
  18. (define (zmuln x y)
  19.   (if (> y -1)
  20.       (zmul x y)
  21.       (- (zmul x (- y)))))
  22.            
  23.      
  24.  
  25.  
  26. (define (zdivizion x y)
  27.   (zdivh x y 1 y))
  28.  
  29. (define (zdivh x y z h)
  30.   (if (= x y)
  31.       z
  32.       (zdivh x (+ y h) (+ 1 z) h)))
  33.  
  34.  
  35.  
  36.  
  37. (test)
Add Comment
Please, Sign In to add comment