Advent of code 2017/6
Ajax Direct

Answer 2637ms

Part 1 : 14029 Part 2 : 2765
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)));