Browse Source

Tower of Hanoi test.

master
Rafal Kupiec 7 months ago
parent
commit
c940224d21
Signed by: belliash <belliash@codingworkshop.eu.org> GPG Key ID: 4E829243E0CFE6B4
2 changed files with 37 additions and 0 deletions
  1. +22
    -0
      tests/tower_of_hanoi.aer
  2. +15
    -0
      tests/tower_of_hanoi.exp

+ 22
- 0
tests/tower_of_hanoi.aer View 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
- 0
tests/tower_of_hanoi.exp View 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…
Cancel
Save