Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def comb(c: Int, r: Int): Int = {
- if(r == 1) c
- else if(r < c) comb(c-1, r-1) + comb(c-1, r)
- else 1
- }
- comb(20,10) //184,756
- def comb(c: Int, r: Int): Int = {
- if(c == 1) r
- else if(c < r) comb(r-1, c-1) + comb(r-1, c)
- else 1
- }
- comb(10,20) //2 -> not right
- def comb(c: Int, r: Int): Int = {
- if (c == 1) r
- else if (c < r) comb(c - 1, r - 1) + comb(c, r - 1)
- else 1
- }
- comb(10, 20) // 184756
- scala> def comb(c: Int, r: Int): Int = {
- | if(r == 1) c
- | else if(r < c) comb(c-1, r-1) + comb(c-1, r)
- | else 1
- | }
- comb: (c: Int, r: Int)Int
- scala> comb(20,10) //184,756
- res0: Int = 184756
- scala> def cc(c: Int, r: Int): Int = {
- | def cc2(c: Int, r: Int): Int = {
- | if(r == 1) c
- | else if(r < c) comb(c-1, r-1) + comb(c-1, r)
- | else 1
- | }
- | if (c < r) cc2(r,c) else cc2(c,r)
- | }
- cc: (c: Int, r: Int)Int
- scala> cc(20,10)
- res1: Int = 184756
- scala> cc(10,20)
- res2: Int = 184756
Add Comment
Please, Sign In to add comment