Created
April 8, 2017 13:59
-
-
Save Fokko/5dbb3ea559e6951ae9a7d558134b9c1d to your computer and use it in GitHub Desktop.
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 frl.driesprong | |
import scala.annotation.tailrec | |
import scala.io.Source | |
object ProblemB extends App { | |
case class ProblemCase(pancakes: List[Boolean], K: Int) | |
val lines = Source.fromFile("/Users/fokkodriesprong/Downloads/B-small-attempt0.in").getLines().toList | |
@tailrec | |
def checkMonotonicIncreasing(sequence: Array[Char]): Boolean = | |
if (sequence.length > 1) | |
if (sequence.head <= sequence.tail.head) | |
checkMonotonicIncreasing(sequence.tail) | |
else | |
false | |
else | |
true | |
@tailrec | |
def solve(number: Long): Long = | |
if (checkMonotonicIncreasing(number.toString.toArray)) | |
number | |
else | |
solve(number - 1) | |
// Get rid of the number of tests | |
val output = lines.tail.map(_.toLong).map(solve).zipWithIndex.map { | |
case (output: Long, idx: Int) => s"Case #${idx + 1}: $output" | |
}.mkString("\n") | |
import java.io._ | |
val pw = new PrintWriter(new File("/Users/fokkodriesprong/Desktop/problemB.txt")) | |
pw.write(output) | |
pw.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment