Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val getBestCellGreedy: Grid => Option[Pair[Int, Int]] = g => {
- val n = g.n
- var bestCell: Option[Pair[Pair[Int, Int], Int]] = None
- for(i <- 0 until n){
- for(j <- 0 until n){
- var possibilities = 0
- if(!g.defined(i,j)){
- for(k <- 1 to n){
- if(g.updated(i,j,k).isConsistent) possibilities += 1
- }
- if(bestCell.isDefined) if(possibilities < bestCell.get._2) bestCell = Option((i,j),possibilities)
- else bestCell = Option((i,j), possibilities)
- }
- }
- }
- var toReturn:Option[Pair[Int, Int]] = None
- if(bestCell.isDefined) toReturn = Option(bestCell.get._1)
- toReturn
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement