Guest User

Untitled

a guest
Jun 2nd, 2010
130
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.  
  4.   private def createList(size: Int): List[Int] = {
  5.     if (size < 1) {
  6.       Nil
  7.     } else if (size % 2 != 0) {
  8.       (size :: createList(size - 1)).reverse
  9.     } else {
  10.       size :: (createList(size - 1).reverse)
  11.     }
  12.   }
  13.  
  14.   override def toString: String = {
  15.     toString(list)
  16.   }
  17.  
  18.   private def toString(list: List[Int]): String = {
  19.     list match {
  20.       case Nil => {
  21.         ""
  22.       }
  23.       case first :: Nil => {
  24.         first.toString
  25.       }
  26.       case first :: remained => {
  27.         first + "-" + toString(remained)
  28.       }
  29.     }
  30.   }
  31. }
  32.  
  33. object App {
  34.   def main(args: Array[String]) {
  35.     for (arg <- args) {
  36.       for (size <- 1 to arg.toInt) {
  37.         println(new Lister(size))
  38.       }
  39.     }
  40.   }
  41. }
RAW Paste Data