1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/examples/hanoi.v

25 lines
308 B
V
Raw Normal View History

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-05-22 18:36:09 +03:00
hanoi(num, 'A','B','C')
2019-12-30 13:25:07 +03:00
}
fn move(n int, a, b string) int {
println('Disc $n from $a to $b\...')
return 0
}
fn hanoi(n int, a, b, c string) int {
if n == 1 {
move(1,a,c)
} else {
hanoi(n-1, a, c, b)
move(n,a,c)
hanoi(n-1, b, a, c)
}
return 0
}