Advertisement
Ilshidur

Triangle de Pascal en Scala

Feb 25th, 2014
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.36 KB | None | 0 0
  1. // Triangle de pascal :
  2.  
  3. def pascal(c: Int, r: Int): Int = {
  4.  
  5.     if ( c > r )
  6.         throw new java.lang.IllegalArgumentException("c > r")
  7.     else if ( c < 0 )
  8.         throw new java.lang.IllegalArgumentException("c < 0")
  9.     else if ( r < 0 )
  10.         throw new java.lang.IllegalArgumentException("r < 0")
  11.     else if ( c==0 || r==c )
  12.         1
  13.     else
  14.         pascal(c, r-1) + pascal(c-1, r-1)
  15.  
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement