/* * Prints instructions to optimally move n discs from peg `src` * to peg `des`. */ fun hanoi(n: Int, src: Int, des: Int) { if (n > 0) { val aux = 6 - src - des hanoi(n-1, src, aux) println("move top disc from peg $src to peg $des") hanoi(n-1, aux, des) } } fun main(args: Array) { val n = args[0].toInt() if (n > 0) hanoi(n, 1, 3) }