Created
June 12, 2015 08:43
-
-
Save sammyrulez/cc5a6f04633a32ab2a22 to your computer and use it in GitHub Desktop.
Cut the sticks
This file contains hidden or 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
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