August 21, 2008 @ 12:20 pm
· Filed under Algorithms, Cars
So, bored with the usual crash tests, some safety engineers decided to see what happens if you take a car with a 5 star safety rating, capable of protecting it’s occupants from a 40 mph head-on crash, and ram it into a wall at 50 mph. The predictable answer is that what is merely an unpleasant experience at 40 mph becomes deadly at 50 mph. I say predictable, because (as we all know from High School physics) force increases as the square of the velocity. A picture is worth a thousand formulas, so here’s the video:
Permalink |
December 30, 2007 @ 8:02 pm
· Filed under Algorithms, PHP
One of an occasional series of posts on PHP algorithms. I found this originally at United Scripters, and bookmarked it for some reason.
Code
function bubbleSort($array=array()/*could have been a pointer*/){
$lastIndex=sizeof($array)-1;
while(true){
$newStartIndex=false;
$newLastIndex=0;
for($j=($startIndex)?$startIndex:1; $j<=$lastIndex; $j++){
if( $array[$j-1] > $array[$j] ){/*SWAP:*/
$temp=$array[$j-1];
$array[$j-1]=$array[$j];
$array[$j]=$temp;
if($newStartIndex===false){$newStartIndex=$j-1;};
$newLastIndex=$j-1;
};
}
if($newStartIndex===false){return $array;};
$startIndex=$newStartIndex;
$lastIndex=$newLastIndex;
}
/* keep this comment to reuse freely:
Orwant, Hietaniemi, Macdonald algorithm as Php implemented by:
http://www.unitedscripters.com */
}
Permalink |