-
-
Save jinuk17/1339f5c27381474db980ed649e38bda6 to your computer and use it in GitHub Desktop.
Cody's jams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pub.jayden.scala.codeport.codysjam | |
object CodysJam extends App{ | |
def solve(jams: List[Long], result: List[Long]) : List[Long] = { | |
if (jams.size > 0) { | |
solve(jams.tail.diff(List(jams.head * 100 / 75)), result:::List(jams.head)) | |
} else { | |
result | |
} | |
} | |
def process(lineIn: Iterator[String])(lineOut: String => Unit) = { | |
for(i <- 1 to lineIn.next().toInt){ | |
lineIn.next() | |
val jams = lineIn.next().split(' ').map(_.toLong).toList | |
val result = solve(jams, List[Long]()).mkString(" ") | |
lineOut(s"Case #$i: $result") | |
} | |
} | |
// val filename = "data/codysjam/example" | |
// val filename = "data/codysjam/A-small-practice" | |
val filename = "data/codysjam/A-large-practice" | |
val writer = new java.io.PrintWriter(filename + ".out") | |
try { | |
process(io.Source.fromFile(filename + ".in").getLines) { s => | |
writer.println(s); writer.flush() | |
} | |
} finally { | |
writer.flush(); writer.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment