Skip to content

Instantly share code, notes, and snippets.

@bongster
Created August 1, 2014 13:22
Show Gist options
  • Save bongster/c79980600af0dac315d6 to your computer and use it in GitHub Desktop.
Save bongster/c79980600af0dac315d6 to your computer and use it in GitHub Desktop.
package main.java
import java.io.FileInputStream
/*
3
2
.#
#.
1 1 2 2
5
.##.#
.....
...#.
.###.
...#.
1 1 5 3
3
...
.#.
...
1 1 3 3
*/
object CrosstheMaze {
def checkNEWS(point: (Int,Int), m: List[String]) : List[Boolean] = {
List(m(point._1 - 1)(point._2) == '.', //N
m(point._1)(point._2 + 1) == '.', //E
m(point._1)(point._2 - 1) == '.', //W
m(point._1 + 1)(point._2) == '.') //S
}
def solve(start: (Int,Int) , end: (Int,Int), m : List[String]): Option[String] = {
println(start,end,m)
val result = checkNEWS(start,m)
result.filter(x => true).length match{
case 3 =>
case 2 =>
case 1 =>
case 0 =>
}
Console println result
None
}
def main(args: Array[String]) {
Console.setIn(new FileInputStream("input.txt"))
val cases = readLine().toInt;
for(n <-(1 to cases)){
val squareSize = readLine.toInt;
val oriMap:List[String] = (for (i <- 1 to squareSize) yield "#" + readLine + "#").toList
val wrapMap:List[String] = List("#" * (squareSize + 2)) ::: oriMap ::: List("#" * (squareSize + 2))
val Array(startX,startY,endX,endY) = readLine.split(" ")
solve((startX.toInt,startY.toInt), (endX.toInt,endY.toInt), wrapMap)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment