Skip to content

Instantly share code, notes, and snippets.

@UberMouse
Created June 5, 2013 03:55
Show Gist options
  • Save UberMouse/5711501 to your computer and use it in GitHub Desktop.
Save UberMouse/5711501 to your computer and use it in GitHub Desktop.
Initial version for CodeEval Query Board
def main(args:Array[String]) {
//val source = scala.io.Source.fromFile(args(0))
val matrix = (new Array[Int](256), new Array[Int](256))
Array("SetCol 32 20",
"SetRow 15 7",
"SetRow 16 31",
"QueryCol 32",
"SetCol 2 14",
"QueryRow 10",
"SetCol 14 0",
"QueryRow 15",
"SetRow 10 1",
"QueryCol 2")
.filter(_.length > 0)
.map(process)
.foreach(x => println(x(matrix)))
}
def process(line:String) = {
val cmdInfo = line split " "
cmdInfo(0) match {
case "SetCol" => setCol(cmdInfo(1), cmdInfo(2)) _
case "SetRow" => setRow(cmdInfo(1), cmdInfo(2)) _
case "QueryCol" => queryCol(cmdInfo(1)) _
case "QueryRow" => queryRow(cmdInfo(1)) _
}
}
def setCol(x:String, y:String)(grid:(Array[Int], Array[Int])) = {s"setCol($x, $y)"}
def setRow(x:String, y:String)(grid:(Array[Int], Array[Int])) = {s"setRow($x, $y)"}
def queryCol(x:String)(grid:(Array[Int], Array[Int])) = {s"queryCol($x)"}
def queryRow(x:String)(grid:(Array[Int], Array[Int])) = {s"queryRow($x)"}
//prints
setCol(32, 20)
setRow(15, 7)
setRow(16, 31)
queryCol(32)
setCol(2, 14)
queryRow(10)
setCol(14, 0)
queryRow(15)
setRow(10, 1)
queryCol(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment