Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. *
  5. * VehicleHistory.com
  6. *
  7. * Online Assessment - Question #3
  8. *
  9. */
  10.  
  11. class Problem
  12. {
  13. public static function combination( $flipOne, $flipTwo, $flipThree )
  14. {
  15. $limit = 1000;
  16.  
  17. $lowestFlip = min( [ $flipOne, $flipTwo, $flipThree ] );
  18. $maxTries = ( $limit - ( $limit % $lowestFlip ) ) / $lowestFlip;
  19.  
  20. $combinations = [];
  21.  
  22. $count = 0;
  23. while ( $count < $maxTries ) {
  24.  
  25. $lowestMultiple = $count * $lowestFlip;
  26.  
  27. if ( $lowestMultiple + $flipOne <= $limit ) {
  28. $combinations[] = $lowestMultiple + $flipOne;
  29. }
  30.  
  31. if ( $lowestMultiple + $flipTwo <= $limit ) {
  32. $combinations[] = $lowestMultiple + $flipTwo;
  33. }
  34.  
  35. if ( $lowestMultiple + $flipThree <= $limit ) {
  36. $combinations[] = $lowestMultiple + $flipThree;
  37. }
  38.  
  39. $count++;
  40. }
  41.  
  42. sort( $combinations );
  43.  
  44. echo implode( "\n", array_unique( $combinations ) );
  45.  
  46. }
  47. }
  48.  
  49. Problem::combination( 10, 15, 55 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement