Reputation: 29
I have a problem with my Racket programm. I want to add this function to my programm but I get stuck in my recursion:
Here the function:
ggt: N x N -> N
(m,n) ->
ggT(m-n,n) if m > n
ggT(m,n-m) if n > m
m if m=n
(define (ggT m n)
(cond
[(> m n)(ggT (- m n)] ;; If m > n the programm should go recursiv back and change
;; the value of m to m-n. But I know that this wont work this way
[(< m n)(ggT (- n m)] ;; Same Problem here
[else m]))
How do I start a real recursion?
Upvotes: 1
Views: 95
Reputation: 62472
Your function ggT
takes two parameters, but you are only passing 1 in. I think you want something like this:
(define (ggT m n)
(cond
[(> m n)(ggT (- m n) n)]
[(< m n)(ggT m (- n m))]
[else m]))
Upvotes: 2
Reputation: 236004
Try this:
(define (ggT m n)
(cond [(> m n) (ggT (- m n) n)]
[(< m n) (ggT m (- n m))]
[else m]))
You just have to pass the parameters in the correct order when calling the ggT
function, remember that ggT
receives two parameters, but you were passing only one.
Upvotes: 3