Advertisement
Guest User

Untitled

a guest
Nov 14th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.59 KB | None | 0 0
  1.   def peers(row: Int, col: Int): List[(Int, Int)] = {
  2.     val rowStart = (row % 3) match {
  3.       case 0 => row
  4.       case 1 => row-1
  5.       case 2 => row-2
  6.     }
  7.     val colStart = (col % 3) match {
  8.       case 0 => col
  9.       case 1 => col-1
  10.       case 2 => col-2
  11.     }
  12.  
  13.     val box = (for (i <- rowStart to rowStart + 2 ; j <- colStart to colStart + 2)
  14.       yield (i, j)).toList
  15.  
  16.     val unfiltered =
  17.     ((for (i <- 0 to 8) yield (row, i)) ++ (for (j <- 0 to 8) yield (j, col))++ box).toList
  18.  
  19.     (unfiltered filter (x => x != (row, col))).toSet.toList //removes duplicates
  20.   }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement