Skip to content

Instantly share code, notes, and snippets.

@felipeska
Created January 17, 2015 22:31
Show Gist options
  • Save felipeska/9010cb2abef93e22fc8e to your computer and use it in GitHub Desktop.
Save felipeska/9010cb2abef93e22fc8e to your computer and use it in GitHub Desktop.
Hanoi in Scala BTW
package com.prodigious.figures
/**
* @author JVM Group
*/
object Hanoi {
def solve(discs: Int, initial: Character, aux: Character, goal: Character) : Unit = {
if (discs > 0) {
solve(discs - 1, initial, goal, aux)
println(s"Move disc from $initial to $goal")
solve(discs - 1, aux, initial, goal)
}
}
def main(args: Array[String]) {
solve(3, 'A', 'B', 'C')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment