src/Alg/Turing/Machine.php
public function run( $input )
	{
		$this->state = $this->start;
		$this->pointer = 0;
		$output = $input;
		$this->wrapTape( $output );
		while( !in_array( $this->state, $this->finals ) )
		{
			if( $_counter > 200 )
				break;
			$_counter++;
			$_current = $this->getCurrent( $output, $this->pointer );
			reset( $this->transition );
			foreach( $this->transition as $trans )
			{
				if( $trans[0] == array( $this->state, $_current ) )
				{
					$value = $trans[1];
					$state = $value[0];
					$this->state = $state;
					$write = $value[1];
					$left = substr( $output, 0, $this->pointer );
					$right = substr( $output, $this->pointer+1 );
					$output = $left.$write.$right;
					$direction = $value[2];
					if( $direction == "l" )
						$this->pointer--;
					else if( $direction == "r" )
						$this->pointer++;
					$this->extendTape( $output, $this->pointer );
					$this->wrapTape( $output );
					break;
				}
			}
			echo $this->showTape( $output );
		}
		$this->cleanTape( $output );
		return $output;
	}
public function run( $input )
	{
		$this->state = $this->start;
		$this->pointer = 0;
		$output = $input;
		$this->wrapTape( $output );
		while( !in_array( $this->state, $this->finals ) )
		{
			if( $_counter > 200 )
				break;
			$_counter++;
			$_current = $this->getCurrent( $output, $this->pointer );
			reset( $this->transition );
			foreach( $this->transition as $trans )
			{
				if( $trans[0] == array( $this->state, $_current ) )
				{
					$value = $trans[1];
					$state = $value[0];
					$this->state = $state;
					$write = $value[1];
					$left = substr( $output, 0, $this->pointer );
					$right = substr( $output, $this->pointer+1 );
					$output = $left.$write.$right;
					$direction = $value[2];
					if( $direction == "l" )
						$this->pointer--;
					else if( $direction == "r" )
						$this->pointer++;
					$this->extendTape( $output, $this->pointer );
					$this->wrapTape( $output );
					break;
				}
			}
			echo $this->showTape( $output );
		}
		$this->cleanTape( $output );
		return $output;
	}
public function run ( $ input ) { $ this -> state = $ this -> start ; $ this -> pointer = 0 ; $ output = $ input ; $ this -> wrapTape ( $ output ) ; while ( ! in_array ( $ this -> state , $ this -> finals ) ) { if ( $ _counter > 200 ) break ; $ _counter ++ ; $ _current = $ this -> getCurrent ( $ output , $ this -> pointer ) ; reset ( $ this -> transition ) ; foreach ( $ this -> transition as $ trans ) { if ( $ trans [ 0 ] == array ( $ this -> state , $ _current ) ) { $ value = $ trans [ 1 ] ; $ state = $ value [ 0 ] ; $ this -> state = $ state ; $ write = $ value [ 1 ] ; $ left = substr ( $ output , 0 , $ this -> pointer ) ; $ right = substr ( $ output , $ this -> pointer + 1 ) ; $ output = $ left . $ write . $ right ; $ direction = $ value [ 2 ] ; if ( $ direction == "l" ) $ this -> pointer -- ; else if ( $ direction == "r" ) $ this -> pointer ++ ; $ this -> extendTape ( $ output , $ this -> pointer ) ; $ this -> wrapTape ( $ output ) ; break ; } } echo $ this -> showTape ( $ output ) ; } $ this -> cleanTape ( $ output ) ; return $ output ; }
Runs the Machine.
@access		public
@param		string		$input			Input to be worked
@return		string
Runs the Machine .