Reputation: 107
Is there a function that count recursive calls for Extended Euclidean algorithm function?
rechnerb :: Integer -> Integer -> (Integer,Integer,Integer)
rechnerb 0 b = (b, 0, 1)
rechnerb a b = let (g, x, y) = rechnerb (b `mod` a) a
in (g, y - (b `div` a) * x, x)
Upvotes: 2
Views: 157
Reputation: 26161
You may do like
rechnerb :: Integer -> Integer -> Int -> ((Integer,Integer,Integer), Int)
rechnerb 0 b c = ((b, 0, 1), c)
rechnerb a b c = let ((g, x, y), cnt) = rechnerb (b `mod` a) a (c+1)
in ((g, y - (b `div` a) * x, x), cnt)
and call like;
λ> rechnerb 7 1100 1 -- last parameter is the initial value (call # 1)
((1,-157,1),3) -- (1,-157,1) is the answer and 3 is the # of calls to rechnerb
Upvotes: 2