Commits

ms shin committed f42a39b

얼렁뚱땅 개미수열 풀이.

Comments (0)

Files changed (1)

src/scala/_homework/anarcher/antseq/antseq.scala

+import collection.mutable.ListBuffer
+
+def e(xs : List[String],x : StringBuffer = new StringBuffer()) : String = xs match {
+    case h :: _ => {
+        x.append("%s%s".format(xs.takeWhile( _ == h ) size , h ))
+        val ys = xs.dropWhile( _ == h )
+        e(ys,x)
+    }
+    case Nil => x.toString
+}
+def antseq(num:Int=7,s:String="1") : List[String] = {
+    val r = new ListBuffer[String]
+    r.append(s)
+    var a = s
+    for(i <- 1 to num) {
+        a = e(a.toList.map( _.toString ))
+        r.append(a)
+    }
+    r.toList
+}
+
+antseq().mkString("\n")