[ create a new paste ] login | about

Link: http://codepad.org/DN0QkN3w    [ raw code | output | fork ]

pauld - PHP, pasted on Jul 16:
<?php
$owidth = 4;
$oheight = 3;
$final = -1;
$wstep = $hstep = 0;
$nos = ($oheight * $owidth);

function calc($step,$check,$change,$last) {
	for($i=$step;$i<$check;++$i){
		$last = $last + $change;
		echo ' '.$last;
	}
	return($last);
}

while($nos > 0){
	// accross
	if ($wstep < $owidth) {
		$final = calc($wstep,$owidth,1,$final);
		$nos = $nos - ($owidth - $wstep);
	
		++$hstep;
		// up
		if ($hstep < $oheight) {
			$final = calc($hstep,$oheight,$owidth,$final);
			$nos = $nos - ($oheight - $hstep);
		
			++$wstep;
			// back
			if ($wstep < $owidth) {
				$final = calc($wstep,$owidth,-1,$final);
				$nos = $nos - ($owidth - $wstep);
			
				++$hstep;
				// down
				if ($hstep < $oheight) {
					$change = 0-$owidth;
					$final = calc($hstep,$oheight,$change,$final);
					$nos = $nos - ($oheight - $hstep);
				}
			}
		}
	}
	++$wstep;
	
}

?>


Output:
1
 0 1 2 3 7 11 10 9 8 4 5 6


Create a new paste based on this one


Comments: