Commits

Anonymous committed 599ed8a

읽고 말하기 수열 완성

Comments (0)

Files changed (1)

src/scala/_homework/miracle0k/LookandSay.scala

+def LookandSay(list : List[Int]) : List[Int] = {
+  val count = list.takeWhile(_ == list.head).size
+  val remainList = list.drop(count)
+
+  remainList match {
+    case Nil => List(count, list.head)
+    case _  => count :: list.head :: LookandSay(remainList) 
+  }
+  
+}
+
+
+//테스트
+var count = 7
+var list = List(1)
+
+while(count > 0) {
+  list = LookandSay(list)
+  println(list)
+  count -= 1
+}
+/*
+// 결과
+11
+21
+1211
+111221
+312211
+13112221
+1113213211
+*/