Created
January 17, 2015 22:31
-
-
Save felipeska/9010cb2abef93e22fc8e to your computer and use it in GitHub Desktop.
Hanoi in Scala BTW
This file contains 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
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