examples: hanoi.v

pull/3271/head
Charles WANG 2019-12-30 18:25:07 +08:00 committed by Alexander Medvednikov
parent ca62b66665
commit 26ee09c9bb
1 changed files with 24 additions and 0 deletions

24
examples/hanoi.v 100644
View File

@ -0,0 +1,24 @@
// hanoi tower
const (
Num = 7
)
fn main() {
hanoi(Num, 'A','B','C')
}
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
}