Skip to content

Instantly share code, notes, and snippets.

@sungkmi
Last active August 29, 2015 14:02
Show Gist options
  • Save sungkmi/24bdeb3d86acd71c0bfd to your computer and use it in GitHub Desktop.
Save sungkmi/24bdeb3d86acd71c0bfd to your computer and use it in GitHub Desktop.
object DeceitfulWar extends App {
def war(naomiSet: Seq[Double], kenSet: Seq[Double], r: Int = 0): Int = {
if(naomiSet.isEmpty) r
else if (naomiSet.length == 1) {
if (naomiSet.head > kenSet.head) 1 else 0
}
else {
val largers = kenSet.filter(_>naomiSet.head)
if (largers.isEmpty) kenSet.size
else war(naomiSet.tail, kenSet diff Seq(largers.head), r+1)
}
}
def dwar(naomi: Seq[Double], ken: Seq[Double]): Int =
0
def process(iter: Iterator[String])(pr: String => Unit) =
for (i <- 1 to iter.next().toInt) yield {
val n = iter.next()
val naomi = iter.next().split(' ').map(_.toDouble)
val ken = iter.next().split(' ').map(_.toDouble)
pr(s"Case #$i: ${dwar(naomi, ken)} ${war(naomi, ken)}")
}
import java.io._
val out = new PrintStream(new File("d.out"))
try {
process(io.Source.fromFile("D-small-practice.in").getLines) { s: String =>
out.println(s)
}
} finally {
out.flush; out.close
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment