PHP

in ita •  24 days ago 

declare(strict_types=1);

function steps(int $number): int{
if($number <=0) throw new InvalidArgumentException('Only positive numbers are allowed');
$counter = 0;
while($number >1){
if($number % 2 ==0){
$number /= 2;
}
else{
$number = 3*$number+1;
}
$counter +=1;
}
return $counter;
}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!