Created
August 1, 2014 13:16
-
-
Save pr-lawrence/1a8a0d5dfb4f72ce9e34 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
package crossTheMaze | |
import scala.io.Source | |
import java.io.File | |
import java.io.PrintWriter | |
object crossTheMazeMain { | |
sealed abstract class Direction { | |
def adj(x: Int, y: Int): List[(Int, Int, Direction)] | |
} | |
object N extends Direction { | |
def adj(x: Int, y: Int) = (x, y - 1, W) :: (x - 1, y, N) :: (x, y + 1, E) :: (x + 1, y, S) :: Nil | |
} | |
object S extends Direction { | |
def adj(x: Int, y: Int) = (x, y + 1, E) :: (x + 1, y, S) :: (x, y - 1, W) :: (x - 1, y, N) :: Nil | |
} | |
object W extends Direction { | |
def adj(x: Int, y: Int) = (x + 1, y, S) :: (x, y - 1, W) :: (x - 1, y, N) :: (x, y + 1, E) :: Nil | |
} | |
object E extends Direction { | |
def adj(x: Int, y: Int) = (x - 1, y, N) :: (x, y + 1, E) :: (x + 1, y, S) :: (x, y - 1, W) :: Nil | |
} | |
case class Edison(var d: Direction, var x: Int, var y: Int) { | |
def isOutside(m: Array[String], x:Int, y:Int) = | |
!(0 <= x && x <= m.size) && !(0 <= y && y <= m(0).size) | |
def next(m: Array[String]): Boolean = { | |
val adjs = d.adj(x, y) | |
val nextPos: Option[(Int, Int, Direction)] = adjs.find { case (xx, yy, _) => | |
!isOutside(m, xx, yy) && m(xx)(yy) == '.' } | |
nextPos match { | |
case Some((xx, yy, dd)) => | |
d = dd | |
x = xx | |
y = yy | |
true | |
case None => false | |
} | |
} | |
} | |
def solve(m: Array[String], sx: Int, sy: Int, ex: Int, ey: Int): String = { | |
"" | |
} | |
def main(args: Array[String]) = { | |
val lines = in.next | |
for (line <- 1 to lines.toInt) { | |
val n = in.next.toInt | |
val m: Array[String] = Array.fill(n)(in.next) | |
m.foreach(println) | |
val Array(sx, sy, ex, ey) = in.next.split(" ").map(_.toInt) | |
println(solve(m, sx - 1, sy - 1, ex - 1, ey - 1)) | |
} | |
} | |
val in = Source.fromFile("small.in").getLines | |
val printerWriter = new PrintWriter(new File("small.out")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment