You are viewing a single comment's thread. Return to all comments →
PHP: wanted to cover all possibilities :P
function kangaroo($x1, $v1, $x2, $v2) { // Write your code here $pk1 = $x1; //position kangaroo No1 $pk2 = $x2; //position kangaroo No2 if ($x1 == $x2 && $v1 != $v2 or $x1 != $x2 && $v1 == $v2 or $x1 > $x2 && $v1 > $v2 or $x1 < $x2 && $v1 < $v2) { return "NO"; }else if ($x1 < $x2) { for ($t=1; $pk1<=$pk2; $t++) { if (($pk1 +($v1*$t)) == ($pk2 + ($v2*$t))) { return "YES"; } else if (($pk1 +($v1*$t)) > ($pk2 + ($v2*$t))) { return "NO"; } } }else if ($x2 < $x1) { for ($t=1; $pk2<=$pk1; $t++) { if (($pk1 +($v1*$t)) == ($pk2 + ($v2*$t))) { return "YES"; } else if (($pk1 +($v1*$t)) < ($pk2 + ($v2*$t))) { return "NO"; } } } else return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
PHP: wanted to cover all possibilities :P