2019-12-30 13:25:07 +03:00
|
|
|
// hanoi tower
|
|
|
|
const (
|
2020-05-22 18:36:09 +03:00
|
|
|
num = 7
|
2019-12-30 13:25:07 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
fn main() {
|
2020-10-26 14:14:21 +03:00
|
|
|
hanoi(num, 'A', 'B', 'C')
|
2019-12-30 13:25:07 +03:00
|
|
|
}
|
|
|
|
|
2021-07-04 17:34:58 +03:00
|
|
|
fn move(n int, a string, b string) {
|
2022-11-15 16:53:13 +03:00
|
|
|
println('Disc ${n} from ${a} to ${b}...')
|
2019-12-30 13:25:07 +03:00
|
|
|
}
|
|
|
|
|
2021-07-04 17:34:58 +03:00
|
|
|
fn hanoi(n int, a string, b string, c string) {
|
2019-12-30 13:25:07 +03:00
|
|
|
if n == 1 {
|
2020-10-26 14:14:21 +03:00
|
|
|
move(1, a, c)
|
2019-12-30 13:25:07 +03:00
|
|
|
} else {
|
2020-10-26 14:14:21 +03:00
|
|
|
hanoi(n - 1, a, c, b)
|
|
|
|
move(n, a, c)
|
|
|
|
hanoi(n - 1, b, a, c)
|
2019-12-30 13:25:07 +03:00
|
|
|
}
|
|
|
|
}
|