progs/lecture2.scala
changeset 95 4fa7231fede7
parent 77 3cbe3d90b77f
child 147 72f7dd1a3754
equal deleted inserted replaced
94:ae4708c851ee 95:4fa7231fede7
   345 // Avoid being mutable
   345 // Avoid being mutable
   346 //=====================
   346 //=====================
   347 
   347 
   348 // a student showed me...
   348 // a student showed me...
   349 import scala.collection.mutable.ListBuffer
   349 import scala.collection.mutable.ListBuffer
       
   350 
       
   351 
   350 
   352 
   351 def collatz_max(bnd: Long): (Long, Long) = {
   353 def collatz_max(bnd: Long): (Long, Long) = {
   352   val colNos = ListBuffer[(Long, Long)]()
   354   val colNos = ListBuffer[(Long, Long)]()
   353   for (i <- (1L to bnd).toList) colNos += ((collatz(i), i))
   355   for (i <- (1L to bnd).toList) colNos += ((collatz(i), i))
   354   colNos.max
   356   colNos.max