lbreda

Robovito

Jun 11th, 2020
1,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2.  
  3. // Config
  4. $n_existing_stickers = 217;
  5. $n_missing_stickers = 8;
  6. $n_packages = 500;
  7. $n_stickers_per_package = 5;
  8. $iterations = 1000;
  9.  
  10. $stickers = range(0, $n_existing_stickers);
  11.  
  12. $success_counter = 0;
  13. for($iteration=0; $iteration<$iterations; $iteration++){
  14.   $missing_stickers = range(0, $n_missing_stickers);
  15.  
  16.   // Generates packages
  17.   $packages = [];
  18.   for($i=0; $i<$n_packages; $i++) {
  19.     shuffle($stickers);
  20.     $packages[] = array_slice($stickers, 0, $n_stickers_per_package);
  21.   }
  22.  
  23.   // Search for stickers
  24.   foreach($packages as $package){
  25.     $missing_stickers = array_diff($missing_stickers, $package);
  26.   }
  27.  
  28.   if(!count($missing_stickers)) $success_counter++;
  29. }
  30. echo "Iterations: {$iterations}\n";
  31. echo "Successes:  {$success_counter}\n";
Advertisement
Add Comment
Please, Sign In to add comment