Skip to content

Instantly share code, notes, and snippets.

@nuboat
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nuboat/5a41dabcfdb53b67e7e7 to your computer and use it in GitHub Desktop.
Save nuboat/5a41dabcfdb53b67e7e7 to your computer and use it in GitHub Desktop.
Thailandoi Programming Contest #2, March
case class HIndex(publishs: List[Int]) {
val checklist = 0.to(publishs.max).sortWith(_ > _)
def calc(): Int = checklist.find(c => rule1(c) && rule2(c)).get
private def refer(c: Int): List[Int] = publishs.filter(_ >= c).toList
private def rule1(c: Int): Boolean = refer(c).size >= c
private def rule2(c: Int): Boolean = refer(c + 1).size <= c
}
object MainHIndex {
private def calinoneline(publishs: List[Int]): String = 0.to(publishs.max).sortWith(_ > _).find(c => (publishs.filter(_ >= c).toList.size >= c) && (publishs.filter(_ >= c + 1).toList.size <= c)).get.toString
def main(args: Array[String]): Unit = {
scala.io.Source.fromFile("Thailandoi Programming Contest/mar_hindex-verifying-input.txt").getLines
.filter(l => l.size > 5)
.foreach(l => println(HIndex(l.substring(5).split(" ").toList.map(_.toInt)).calc))
println("===================")
scala.io.Source.fromFile("Thailandoi Programming Contest/mar_hindex-input.txt").getLines
.filter(l => l.size > 5)
.foreach(l => println(HIndex(l.substring(5).split(" ").toList.map(_.toInt)).calc))
println("===================")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment