3v4l.org

run code in 300+ PHP versions simultaneously
<?php $lizards = []; for ($i = 0; $i < 15; $i++) { $lizards[] = 1; } for ($i = 0; $i < 7; $i++) { $lizards[] = 2; } for ($i = 0; $i < 8; $i++) { $lizards[] = 3; } srand(time()); for ($i = 0; $i < 10000; $i++) { $a1 = mt_rand(0, count($lizards) - 1); do { $a2 = mt_rand(0, count($lizards) - 1); } while ($a1 == $a2); if ($lizards[$a1] == $lizards[$a2]) { continue; } $new_color = 6 - $lizards[$a1] - $lizards[$a2]; $lizards[$a1] = $new_color; $lizards[$a2] = $new_color; $colors_count = (in_array(1, $lizards) ? 1 : 0) + (in_array(2, $lizards) ? 1 : 0) + (in_array(3, $lizards) ? 1 : 0); if ($colors_count == 1) { echo "Остался только один цвет\n"; break; } $counts = [null, 0, 0, 0]; foreach ($lizards as $color) { $counts[$color]++; } echo sprintf("%s\t%s\t%s\n", $counts[1], $counts[2], $counts[3]); } ?>

preferences:
24.99 ms | 408 KiB | 5 Q