Guest User

Untitled

a guest
Jun 2nd, 2010
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Lister(size: Int) {
  2.   private val list: List[Int] = createList(size)
  3.   private def createList(size: Int): List[Int] =
  4.     if (size < 1) Nil
  5.     else if (size % 2 != 0) (size :: createList(size - 1)).reverse
  6.     else size :: (createList(size - 1).reverse)
  7.   override def toString: String = toString(list)
  8.   private def toString(list: List[Int]): String = list match {
  9.     case Nil => ""
  10.     case first :: Nil => first.toString
  11.     case first :: remained => first + "-" + toString(remained)
  12.   }
  13. }
  14.  
  15. for (arg <- args)
  16.   for (size <- 1 to arg.toInt)
  17.     println(new Lister(size))
RAW Paste Data