indy256's blog

By indy256, 11 years ago, In English

Hi. For those who like to solve CodeJam in multiple programming languages, here https://github.com/indy256/codejam-templates is a collection of templates which reveal basic language constructs.

Currenly there are 8 single-threaded templates in Java, C++, Ruby, Python, JavaScript, etc.

Contribution of additional languages is welcomed.

  • Vote: I like it
  • +16
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Contribution of additional languages is welcomed

ok, there is my pull request: https://github.com/indy256/codejam-templates/pull/1/files

»
11 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Scala (multithreaded) template


import scala.concurrent.duration._ import scala.concurrent._ import ExecutionContext.Implicits.global object Main { val in = new java.util.Scanner(System.in) def nextInt = in.next().toInt def nextDouble = in.next().toDouble def main(args: Array[String]): Unit = { val taskCount = nextInt val tasks = for (test <- 1 to taskCount) yield { val op = in.next val n = nextInt val vals = Seq.fill(n)(nextDouble) def solve() = op match { case "median" => vals.sorted.apply(n / 2) case "mean" => vals.sum / n } future { s"Case #${test}: " + solve() } } val all = Future.sequence(tasks) val result = Await.result(all, 8 minutes) result foreach println } }