scala - 迭代器 toIndexedSequence 长度与插入器长度不匹配
问题描述
在迭代器上调用 toIndexedSequence 时遇到一个奇怪的错误。迭代器的长度为 81,但生成的 indexedSequence 的长度为 257。当我打印 indexedSequence 时,我得到两个向量。第一个是 81 的正确长度,但它打印的第二个是 257。我不确定它为什么会打印两个向量。第二个似乎是在我的元素之间添加零。
def apply(source: scala.io.Source): Sudoku = {
val vec = for( x <- source.toVector if !isWhiteSpace(x) ) yield { if( x>='1' && x<='9') x - 48 else 0 }
println( vec )
new Sudoku(vec)
}
def isWhiteSpace( char: Char ):Boolean = char == (' ' | '\n')
ouput:
Vector(9, 0, 0, 0, 8, 3, 0, 1, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 4, 0, 0, 0, 0, 7, 0, 0, 6, 0, 5, 0, 0, 0, 1, 0, 4, 0, 3, 0, 0, 0, 6, 0, 9, 0, 0, 7, 0, 0, 0, 0, 9, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 0, 4, 0, 5, 2, 0, 0, 0, 6)
Vector(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 3, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 5, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0)
解决方案
推荐阅读
- python - 如何停止使用字符串处理整数的while循环
- kotlin - 使用来自 IntelliJ 的绑定运行 Kotlin 脚本 (.kts) - 未解决的参考:绑定
- haskell - 如何阻止布列塔尼扩展括号以进行对齐
- html - 使用 scroll-snap-type 在 Chrome 上双滚动网站
- jquery - Laravel - 使用现有行数据创建新用户
- c# - ASP .NET 中的全局异常过滤器
- ios - 弹出框关闭后,如何在 PageViewController 上显示警报?
- javascript - 如何将 css 样式从文件注入到 WebComponent
- flutter - 我使用了很多容器小部件。我做得对吗?
- amazon-web-services - IAM CodeBuild 策略条件 - 委托人标签等于资源标签