Created
March 31, 2011 12:32
-
-
Save bjartek/896275 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val input = "..*\n...\n*.."; | |
val grid = input.split("\n").map(_.toArray) | |
def bomb(coord: Tuple2[Int,Int]) = { | |
for{ | |
row <- grid.lift(coord._1) | |
cell <- row.lift(coord._2) | |
if(cell == '*') | |
} yield 1 | |
} | |
def nearby(x:Int, y:Int) = for( row <- x-1 to x+1; col <- y-1 to y+1) yield (row,col) | |
def score(x:Int, y:Int) : String = bomb2(x,y) match { | |
case Some(x) => " " | |
case None => nearby(x,y).flatMap(bomb2).sum.toString | |
} | |
var cells = grid.indices.map( x => grid(x).indices.map( y => score(x,y))) | |
cells.foreach(x => println(x.mkString)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment