Guest User

Untitled

a guest
Jul 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /**
  2. * Part 2.
  3. * Now there are two image arrays with different "weights", X and Y. Update your function so there is an X/(X+Y)% chance that
  4. * each image in the subset is selected from the first array, and a Y/(X+Y)% chance that the image is selected from the second array.
  5. * The returned subset should still be 1 dimensional, as in part 2.
  6. * Picking unique images is more important than the weights. i.e. if the subset isn't filled and there are no more images available in X
  7. * the remaining slots should be drawn exclusively from Y, and vice versa.
  8. * */
  9.  
  10. $xImages = array('weight' => 3, 'images' => array('x1.jpg', 'x2.jpg', 'x3.jpg', 'x4.jpg', 'x5.jpg', 'x6.jpg')); //75%
  11. $yImages = array('weight' => 1, 'images' => array('y1.jpg', 'y2.jpg', 'y3.jpg', 'y4.jpg', 'y5.jpg', 'y6.jpg')); //25%
  12. $images = array($xImages, $yImages);
  13.  
  14. $imageSetWeighted = selectWeighted($images, 6);
  15. echo '6: <pre>' . print_r($imageSetWeighted, true) . '</pre>';
  16. $imageSetWeighted = selectWeighted($images, 8);
  17. echo '8: <pre>' . print_r($imageSetWeighted, true) . '</pre>';
  18. $imageSetWeighted = selectWeighted($images, 16);
  19. echo '16: <pre>' . print_r($imageSetWeighted, true) . '</pre>';
  20.  
  21. function selectWeighted($images, $number) {
  22.  
  23. }
Add Comment
Please, Sign In to add comment