progs/lecture1.scala
changeset 329 8a34b2ebc8cc
parent 316 8b57dd326a91
child 335 7e00d2b13b04
equal deleted inserted replaced
328:0e591f806290 329:8a34b2ebc8cc
   423 //
   423 //
   424 // Remember:
   424 // Remember:
   425 // - no vars, no ++i, no +=
   425 // - no vars, no ++i, no +=
   426 // - no mutable data-structures (no Arrays, no ListBuffers)
   426 // - no mutable data-structures (no Arrays, no ListBuffers)
   427 
   427 
   428 // But what the heck....
   428 // But what the heck....lets try to count to 1 Mio in parallel
       
   429 
       
   430 var cnt = 0
       
   431 
       
   432 for(i <- (1 to 1000000).par) cnt += 1
       
   433 
       
   434 println(s"Should be 1 Mio: $cnt")
       
   435 
       
   436 
       
   437 
       
   438 // Or
   429 // Q: Count how many elements are in the intersections of 
   439 // Q: Count how many elements are in the intersections of 
   430 //    two sets?
   440 //    two sets?
   431 // A; IMPROPER WAY (mutable counter)
   441 // A; IMPROPER WAY (mutable counter)
   432 
   442 
   433 def count_intersection(A: Set[Int], B: Set[Int]) : Int = {
   443 def count_intersection(A: Set[Int], B: Set[Int]) : Int = {