0) { $this->chars = $alphabet; } $this->c = new OneChar($current, $this->chars); } function increase() { $this->c->increase(); } function build() { return $this->c->build(); } } class OneChar { private $chars; private $otherChar = NULL; private $pos = 0; function __construct($s, $ch) { $this->chars = $ch; $current = substr($s, -1, 1); $this->pos = strpos($this->chars, $current); $s = substr($s, 0, strlen($s)-1); if (strlen($s) > 0) { $this->otherChar = new OneChar($s, $ch); } } function increase() { $this->pos = $this->pos + 1; if ($this->pos >= strlen($this->chars)) { $this->pos = 0; if ($this->otherChar != NULL) { $this->otherChar->increase(); } else { $this->otherChar = new OneChar($this->chars[0], $this->chars); } } } function build() { if ($this->otherChar != NULL) { return $this->otherChar->build() . $this->chars[$this->pos]; } return $this->chars[$this->pos]; } }