All pastes #144168 Raw Edit

Fibonacci-calc

public php v1 · immutable
#144168 ·published 2006-08-22 11:41 UTC
rendered paste body
<?php$str = (isset($_GET['str']) && $_GET['str'] != '') ? $_GET['str'] : '1';$nbr_it = (isset($_GET['nbr_it']) && $_GET['nbr_it'] != '') ? $_GET['nbr_it'] : '50';function loop_and_look($pos, $sstr) {	$tmp_str = '';	if(isset($sstr{$pos+1}) && $sstr{$pos+1} == $sstr{$pos}) {		if(isset($sstr{$pos+2}) && $sstr{$pos+2} == $sstr{$pos}) {			$tmp_str = '3'. $sstr{$pos};			if(isset($sstr{$pos+3})) $tmp_str .= loop_and_look($pos+3, $sstr);		} else {			$tmp_str = '2'. $sstr{$pos};			if(isset($sstr{$pos+2})) $tmp_str .= loop_and_look($pos+2, $sstr);		}	} else {		$tmp_str = '1'. $sstr{$pos};		if(isset($sstr{$pos+1})) $tmp_str .= loop_and_look($pos+1, $sstr);	}	return $tmp_str;}function replace_by_code($sstr) {	$list_f_pattern = array(		'000', '999', '888', '777', '666', '555', '444', '333', '222', '111', '00', '99', '88', '77', '66',		 '55', '44', '33', '22', '11', '0', '9', '8', '7', '6', '5', '4', '3', '2', '1'	);	$list_f_replace = array(		'j-j-j', 'i-i-i', 'h-h-h', 'g-g-g', 'f-f-f', 'e-e-e', 'd-d-d', 'c-c-c', 'b-b-b', 'a-a-a', 'j-j',		 'i-i', 'h-h', 'g-g', 'f-f', 'e-e', 'd-d', 'c-c', 'b-b', 'a-a', 'j', 'i', 'h', 'g', 'f', 'e', 'd',		 'c', 'b', 'a'	);	$list_a_pattern = array(		'j-j-j', 'i-i-i', 'h-h-h', 'g-g-g', 'f-f-f', 'e-e-e', 'd-d-d', 'c-c-c', 'b-b-b', 'a-a-a', 'j-j',		'i-i', 'h-h', 'g-g', 'f-f', 'e-e', 'd-d', 'c-c', 'b-b', 'a-a', 'j', 'i', 'h', 'g', 'f', 'e', 'd',		 'c', 'b', 'a'	);	$list_a_replace = array(		'30', '39', '38', '37', '36', '35', '34', '33', '32', '31', '20', '29', '28', '27', '26', '25', '24',		'23', '22', '21', '10', '19', '18', '17', '16', '15', '14', '13', '12', '11'	);	$tmp_str = '';	$tmp_str = str_replace($list_f_pattern, $list_f_replace, $sstr);	$sstr = str_replace($list_a_pattern, $list_a_replace, $tmp_str);	return $sstr;}$time_pre_start = explode(' ', microtime());$time_start = $time_pre_start[1] + $time_pre_start[0];for($rnd = 0; $rnd < $nbr_it; $rnd++) {	$len = strlen($str);	if($rnd <= 15) {		$str = loop_and_look(0, $str);	} else {		$str = replace_by_code($str);	}	echo $rnd ." : ". $str ."<br />\r\n";}$time_pre_end = explode(' ', microtime());$time_end = $time_pre_end[1] + $time_pre_end[0];$time = $time_end - $time_start;echo $time .' secondes !';?>