class BulbRow { private $row = array(); private $iteration = 0; function __construct($size = 100) { $this->row = array_fill(1, $size, false); } // Go to a specified iteration. function GoTo($target) { // If the target is closer to 0 than to current iteration, start over // from there. If the distance is the same, it's easier not to start // over. if($target < ($this->iteration / 2)) { $this->__construct(count($this->row)); } // Decide whether we're counting up or down $direction = ($target > $this->iteration) ? 1 : -1; // For each step between the current iteration and the target, for($i = $this->iteration; $i != $target; $i += $direction) { // Count each light to be flipped on this iteration, for($j = $i; $j <= 100; $j += $i) { // Flip it! $this->row[$j] = !$this->row[$j]; } } } function PrintOut() { } }