Skip to content

Instantly share code, notes, and snippets.

@tksk
Created February 7, 2014 15:50
Show Gist options
  • Save tksk/8865339 to your computer and use it in GitHub Desktop.
Save tksk/8865339 to your computer and use it in GitHub Desktop.
// http://nabetani.sakura.ne.jp/hena/ord13updowndouble/
object PlusMinusDouble extends App {
def solve(list: List[(Int, Int)]): Int = list match {
case (n, 0) :: _ => n
case (n, x) :: xs if x % 2 != 0 =>
solve(xs :+ (n+1, x+1) :+ (n+1, x-1))
case (n, x) :: xs =>
solve(xs :+ (n+1, x/2))
}
val problem = args(0).toInt
println(solve(List((0, problem))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment