Skip to content

Instantly share code, notes, and snippets.

@sammyrulez
Created June 12, 2015 08:43
Show Gist options
  • Save sammyrulez/cc5a6f04633a32ab2a22 to your computer and use it in GitHub Desktop.
Save sammyrulez/cc5a6f04633a32ab2a22 to your computer and use it in GitHub Desktop.
Cut the sticks
object Sticks {
def main(args: Array[String]): Unit = {
val input: Array[Int] = args.map(_.toInt)
val sticks = new Sticks
sticks.cutSticks(input)
}
}
class Sticks {
def cutSticks(input: Array[Int]): Array[Int] = {
val length: Int = input.length
length match {
case 0 => exit()
case _ => {
println(length)
val min: Int = input.sorted.head
val reduced = input.map(_ - min)
val out = reduced.filter(_ > 0)
return cutSticks(out)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment