progs/lecture2.scala
changeset 98 44a20e85dd38
parent 95 4fa7231fede7
child 147 3e5d8657302f
equal deleted inserted replaced
97:3db70bdce7a4 98:44a20e85dd38
   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