Scala solution to nQueen using for-comprehension
问题 I have some difficulty in understanding the Scala solution to the n Queens problem, below is the implementation assuming isSafe is defined correctly def queens(n: Int): Set[List[Int]] = { def placeQueens(k: Int): Set[List[Int]] = k match { case 0 => Set(List()) case _ => for { queens <- placeQueens(k - 1) col <- 0 until n if isSafe(col, queens ) }yield k :: queens } placeQueens(n) } The for comprehension, as I have seen, theoretically should return a buffered collection, and I see here it