我的任务:
- 实现一个函数来计算Look-and-say序列。
完成后,测试成功通过:
import scala.collection.immutable.LazyList
import scala.language.implicitConversions
import scala.collection.mutable.ListBuffer
object CountAndSay extends App {
def nextLine(currentLine: List[BigInt]): List[BigInt] = {
...
println(nextLine(List(1, 2, 1, 1)) == List(1, 1, 1, 2, 2, 1))
println(nextLine(List(1, 1, 1, 2, 2, 1)) == List(3, 1, 2, 2, 1, 1))
println(nextLine(List(3, 1, 2, 2, 1, 1)) == List(1, 3, 1, 1, 2, 2, 2, 1))
}
- 实现一个生成给定序列的惰性列表。
val funSeq: LazyList[List[Int]] = ...
println(funSeq(5) === List(3, 1, 2, 2, 1, 1))
要创建带有嵌套列表的 LazyList,我想使用 LazyList.iterate。 LazyList.iterate 描述 但我收到无法解析重载方法“迭代”错误:
val funSeq: LazyList[List[BigInt]] = LazyList.iterate(List(1), nextLine(List(1)))
我将不胜感激任何帮助。