Advent of code 2016/19
Ajax Direct

Answer 1ms

Part 1 : 1834471 Part 2 : 1420064
/**
 * Explaination : For both parts, I simulated results up to 1000
 * and found an equation that could be used.
 */

$input = $input->int;

// ==================================================
// > PART 1
// ==================================================
$solution_1 = ($input - (2 ** (strlen(decbin($input)) - 1))) * 2 + 1;

// ==================================================
// > PART 2
// ==================================================
$n = $s = 2;
while (($n = ($n * 3 - 2)) <= $input) $s = $n;
$n = $input - $s + 1;

$solution_2 = $n <= $s ? $n : 2 * $n - $s + 1;