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);