rdc
11/11/2017 - 2:48 AM

PHP - 3n Algorithm

PHP - 3n Algorithm

for(;$num1 <= $num2; $num1++) {
    $k = 1;
    $num=$num1;
    while($num != 1) {
        $num = ($num % 2 == 0) ? ($num / 2) : (3 * $num + 1);
        $k++;
         if($k > $l) {
            $l = $k;
        }
    }
}