Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Config
- $n_existing_stickers = 217;
- $n_missing_stickers = 8;
- $n_packages = 500;
- $n_stickers_per_package = 5;
- $iterations = 1000;
- $stickers = range(0, $n_existing_stickers);
- $success_counter = 0;
- for($iteration=0; $iteration<$iterations; $iteration++){
- $missing_stickers = range(0, $n_missing_stickers);
- // Generates packages
- $packages = [];
- for($i=0; $i<$n_packages; $i++) {
- shuffle($stickers);
- $packages[] = array_slice($stickers, 0, $n_stickers_per_package);
- }
- // Search for stickers
- foreach($packages as $package){
- $missing_stickers = array_diff($missing_stickers, $package);
- }
- if(!count($missing_stickers)) $success_counter++;
- }
- echo "Iterations: {$iterations}\n";
- echo "Successes: {$success_counter}\n";
Advertisement
Add Comment
Please, Sign In to add comment