$n){ $pos -= substr_count(decbin($pos),1,0); if ($pos == $visited){ $count = -1; break; } $visited = $pos; $count++; } $pos = move($pos); $count++; } echo $count .PHP_EOL; function move($param){ $param += substr_count(decbin($param),1,0); return $param; }