Advent of code 2016/16
Ajax Direct

Answer

Part 1 :
Part 2 :
function solve ($state, $disk) {
    // Fill disk
    while (strlen($state) < $disk) {
        $state .= "0" . str_replace(["0", "1", "#"], ["#", "0", "1"], strrev($state));
    }
    $state = substr($state, 0, $disk);

    // Get odd checksum
    while (true) {
        $checksum = "";

        for ($i = 0; $i < strlen($state) - 1; $i += 2) {
            $checksum .= $state[$i] == $state[$i + 1] ? 1 : 0;
        }

        if (strlen($checksum) % 2) return $checksum;
        $state = $checksum;
    }
}

// ==================================================
// > SOLUTION
// ==================================================
$solution_1 = solve($input, 272);
$solution_2 = solve($input, 35651584);