Mercurial > repos > icfp2013
diff tools/parse.scala @ 1:cdfc5e2de435
Checking in our problem set and a simple scala parser
author | Joshua Garnett <josh.garnett@gmail.com> |
---|---|
date | Thu, 08 Aug 2013 21:08:01 -0400 |
parents | |
children | 5cf8de487ed6 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/parse.scala Thu Aug 08 21:08:01 2013 -0400 @@ -0,0 +1,35 @@ +// +// How to run: scala -cp json-smart-1.0.9-1.jar parse.scala +// +import net.minidev.json._ +import scala.collection.JavaConversions._ +import scala.collection.mutable._ + +val file = scala.io.Source.fromFile("../data/myproblems.json").mkString +val json = JSONValue.parse(file).asInstanceOf[JSONArray] + +var totalProblems = json.size +var totalSize = 0 +val operatorHash = HashMap[String, Int]() + +for(p <- json) { + val problem = p.asInstanceOf[JSONObject] + totalSize += problem.get("size").asInstanceOf[java.lang.Integer] + val operators = problem.get("operators").asInstanceOf[JSONArray] + for(o <- operators) { + val operator = o.asInstanceOf[String] + operatorHash(operator) = operatorHash.get(operator) match { + case Some(count) => count + 1 + case None => 1 + } + } +} + +println("Total problems: " + totalProblems) +println("Total size: " + totalSize) +println("Average size: " + totalSize / totalProblems) + +println("Operator Count: ") +for((key, value) <- operatorHash) { + println(" " + key + ":" + value) +}