Skip to content

Instantly share code, notes, and snippets.

@jackliusr
Last active August 29, 2015 14:04
Show Gist options
  • Save jackliusr/4b50885057eefdb66234 to your computer and use it in GitHub Desktop.
Save jackliusr/4b50885057eefdb66234 to your computer and use it in GitHub Desktop.
Hackerrank Filling Jars in Scala. need more performant implementation
object Solution {
def main(args: Array[String]) {
val lines = io.Source.stdin.getLines().toList
val jars = lines(0).split("\\s+")(0).toInt
val ops = lines.drop(1).map( l => l.split("\\s+").map(s => s.toLong))
val rslt = ops.foldLeft(0L)( (acc, v) => acc + ( (v(1) - v(0) + 1) * v(2) ))
println(rslt / jars)
}
}
@jackliusr
Copy link
Author

the performant implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment