Skip to content

Instantly share code, notes, and snippets.

@Fokko
Created April 8, 2017 13:59
Show Gist options
  • Save Fokko/5dbb3ea559e6951ae9a7d558134b9c1d to your computer and use it in GitHub Desktop.
Save Fokko/5dbb3ea559e6951ae9a7d558134b9c1d to your computer and use it in GitHub Desktop.
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