Advent of code 2017/6
Ajax Direct

Answer

Part 1 :
Part 2 :
function solve($blocks) {
    $states = [];

    while (!in_array($blocks, $states)) {
        $states[] = $blocks;

        $max   = max($blocks);
        $start = array_search($max, $blocks);
        $blocks[$start] = 0;

        for ($i = 0; $i < $max; $i++) {
            $blocks[($start + $i + 1) % count($blocks)]++;
        }
    }

    return $states;
}

// ==================================================
// > SOLUTIONS
// ==================================================
$states = solve((array) $input->numbers());

$solution_1 = count($states);
$solution_2 = count(solve(end($states)));