Advertisement
Madotsuki

divalg in 3 ways

Sep 5th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. divalg a b = if a < b then (0,a)
  2.              else
  3.                 let (q,r) = divalg (a-b) b
  4.                 in (q+1,r)
  5.  
  6. divalg a b | a < b = (0,a)
  7.              otherwise = let (q,r) = divalg (a-b) b
  8.                          in (q+1,r)
  9.  
  10. divalg a b | a < b = (0,a)
  11.             | otherwise = (q+1,r) where
  12.                         (q,r) = divalg (a-b) b
  13.                        
  14.                        
  15. -- Function trace (example)
  16. divalg 14 6 = if 14 < 6 then (0,14) else let(q,r) = divalg 8 6 in (q+1,r) -- False, so do the else statement
  17.             = let (q,r) = divalg 8 6 in (q+1,r) -- This is the else statement
  18.             = let (q,r) = if 8 < 6 then (0,8) else let (q,r) = divalg 2 6 in (q+1,r) -- False again, do the else statement...
  19.             = let (q,r) = let(q,r) = divalg 2 6 in (q+1,r) -- Else statement here :trololo:
  20.             = let (q,r) = let(q,r) = if 2 < 6 then 0,2) else let (q,r) = divalg (-4) 6 in (q+1+r) in (q+1+r) -- Condition met, do the true statement now
  21.             = let (q,r) = let(q,r) = (0,2) in (q+1,r) in (q+1,r) -- We got the info! Let's pass it back.
  22.             = let (q,r) = (1,2) in (q+1,r) -- Passing it back,
  23.             = (2,2) -- Done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement