Advertisement
Guest User

ProjectEuler1.scala

a guest
Oct 7th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.31 KB | None | 0 0
  1. /*execute with: $ scala name_of_file.scala*/
  2.  
  3. def ProjectEuler1(limit:Long) = {
  4.     def rec(sum:Long , limit:Long , cur:Long):Long = {
  5.         if (limit==cur) sum
  6.         else if ( cur%3==0 || cur%5 == 0) rec(sum+cur,limit,cur+1)
  7.         else rec(sum,limit,cur+1)
  8.     }
  9.     rec(0,limit,1)
  10.   }
  11.  
  12. println(ProjectEuler1(1000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement