Guest User

Untitled

a guest
Jan 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. def comb(c: Int, r: Int): Int = {
  2. if(r == 1) c
  3. else if(r < c) comb(c-1, r-1) + comb(c-1, r)
  4. else 1
  5. }
  6. comb(20,10) //184,756
  7.  
  8. def comb(c: Int, r: Int): Int = {
  9. if(c == 1) r
  10. else if(c < r) comb(r-1, c-1) + comb(r-1, c)
  11. else 1
  12. }
  13. comb(10,20) //2 -> not right
  14.  
  15. def comb(c: Int, r: Int): Int = {
  16. if (c == 1) r
  17. else if (c < r) comb(c - 1, r - 1) + comb(c, r - 1)
  18. else 1
  19. }
  20.  
  21. comb(10, 20) // 184756
  22.  
  23. scala> def comb(c: Int, r: Int): Int = {
  24. | if(r == 1) c
  25. | else if(r < c) comb(c-1, r-1) + comb(c-1, r)
  26. | else 1
  27. | }
  28. comb: (c: Int, r: Int)Int
  29.  
  30. scala> comb(20,10) //184,756
  31. res0: Int = 184756
  32.  
  33. scala> def cc(c: Int, r: Int): Int = {
  34. | def cc2(c: Int, r: Int): Int = {
  35. | if(r == 1) c
  36. | else if(r < c) comb(c-1, r-1) + comb(c-1, r)
  37. | else 1
  38. | }
  39. | if (c < r) cc2(r,c) else cc2(c,r)
  40. | }
  41. cc: (c: Int, r: Int)Int
  42.  
  43. scala> cc(20,10)
  44. res1: Int = 184756
  45.  
  46. scala> cc(10,20)
  47. res2: Int = 184756
Add Comment
Please, Sign In to add comment