Mercurial > repos > icfp2013
view tools/parse.scala @ 43:96b2fcb746bf
Add support for generating programs with only a certain set of operators to allow work with slightly larger problem sizes
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 11 Aug 2013 02:16:14 -0700 |
parents | 5cf8de487ed6 |
children |
line wrap: on
line source
// // 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]() val allSizes = HashMap[Int, Int]() for(p <- json) { val problem = p.asInstanceOf[JSONObject] val size = problem.get("size").asInstanceOf[java.lang.Integer] totalSize += size val operators = problem.get("operators").asInstanceOf[JSONArray] allSizes(size) = allSizes.get(size) match { case Some(count) => count + 1 case None => 1 } 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) } println("Size Count: ") for(key <- allSizes.keys.toList.sorted) { println(" " + key + ":" + allSizes(key)) }