Advertisement
Guest User

Untitled

a guest
May 5th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.68 KB | None | 0 0
  1.  val getBestCellGreedy: Grid => Option[Pair[Int, Int]] = g => {
  2.     val n = g.n
  3.     var bestCell: Option[Pair[Pair[Int, Int], Int]] = None
  4.     for(i <- 0 until n){
  5.       for(j <- 0 until n){
  6.         var possibilities = 0
  7.         if(!g.defined(i,j)){
  8.           for(k <- 1 to n){
  9.             if(g.updated(i,j,k).isConsistent) possibilities += 1
  10.           }
  11.           if(bestCell.isDefined) if(possibilities < bestCell.get._2) bestCell = Option((i,j),possibilities)
  12.           else bestCell = Option((i,j), possibilities)
  13.         }        
  14.       }
  15.     }
  16.     var toReturn:Option[Pair[Int, Int]] = None
  17.     if(bestCell.isDefined) toReturn = Option(bestCell.get._1)
  18.     toReturn
  19.    
  20.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement