Блог пользователя indy256

Автор indy256, 10 лет назад, По-английски

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.

  • Проголосовать: нравится
  • +16
  • Проголосовать: не нравится

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Contribution of additional languages is welcomed

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

»
10 лет назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

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 } }