This commit is contained in:
parent
3eb82e632b
commit
c940224d21
22
tests/tower_of_hanoi.aer
Normal file
22
tests/tower_of_hanoi.aer
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
class Hanoi {
|
||||||
|
|
||||||
|
public void towerOfHanoi(int $diskCount, int $fromPole, int $toPole, int $viaPole) {
|
||||||
|
if($diskCount == 1) {
|
||||||
|
printf('Move disk from pole ' + $fromPole + ' to pole ' + $toPole + "\n");
|
||||||
|
} else {
|
||||||
|
$this->towerOfHanoi($diskCount - 1, $fromPole, $viaPole, $toPole);
|
||||||
|
$this->towerOfHanoi(1, $fromPole, $toPole, $viaPole);
|
||||||
|
$this->towerOfHanoi($diskCount - 1, $viaPole, $toPole, $fromPole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Program {
|
||||||
|
|
||||||
|
public void main() {
|
||||||
|
object $hanoi = new Hanoi();
|
||||||
|
$hanoi->towerOfHanoi(4, 1, 2, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
tests/tower_of_hanoi.exp
Normal file
15
tests/tower_of_hanoi.exp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Move disk from pole 1 to pole 3
|
||||||
|
Move disk from pole 1 to pole 2
|
||||||
|
Move disk from pole 3 to pole 2
|
||||||
|
Move disk from pole 1 to pole 3
|
||||||
|
Move disk from pole 2 to pole 1
|
||||||
|
Move disk from pole 2 to pole 3
|
||||||
|
Move disk from pole 1 to pole 3
|
||||||
|
Move disk from pole 1 to pole 2
|
||||||
|
Move disk from pole 3 to pole 2
|
||||||
|
Move disk from pole 3 to pole 1
|
||||||
|
Move disk from pole 2 to pole 1
|
||||||
|
Move disk from pole 3 to pole 2
|
||||||
|
Move disk from pole 1 to pole 3
|
||||||
|
Move disk from pole 1 to pole 2
|
||||||
|
Move disk from pole 3 to pole 2
|
Loading…
Reference in New Issue
Block a user