shuffleArray($snapshot); $expected = []; $cursor = 0; for ($rank = 0; $rank <= $act['alternates_per_prize']; $rank++) { foreach ($prizes as $prize) { if (! isset($ordered[$cursor])) { break 2; } $expected[] = ['position' => (int) $prize['position'], 'rank' => $rank, 'ticket' => $ordered[$cursor++]['ticket']]; } } $actual = array_map(fn ($w) => ['position' => (int) $w['position'], 'rank' => (int) $w['rank'], 'ticket' => $w['ticket']], $act['winners']); $sort = fn ($a, $b) => [$a['rank'], $a['position']] <=> [$b['rank'], $b['position']]; usort($actual, $sort); usort($expected, $sort); if ($actual !== $expected) { throw new RuntimeException('Las asignaciones no coinciden con el cálculo reproducido.'); } fwrite(STDOUT, "Compromisos y asignaciones verificados.\n"); } catch (Throwable $e) { fwrite(STDERR, $e->getMessage()."\n"); exit(1); }