Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * VehicleHistory.com
- *
- * Online Assessment - Question #3
- *
- */
- class Problem
- {
- public static function combination( $flipOne, $flipTwo, $flipThree )
- {
- $limit = 1000;
- $lowestFlip = min( [ $flipOne, $flipTwo, $flipThree ] );
- $maxTries = ( $limit - ( $limit % $lowestFlip ) ) / $lowestFlip;
- $combinations = [];
- $count = 0;
- while ( $count < $maxTries ) {
- $lowestMultiple = $count * $lowestFlip;
- if ( $lowestMultiple + $flipOne <= $limit ) {
- $combinations[] = $lowestMultiple + $flipOne;
- }
- if ( $lowestMultiple + $flipTwo <= $limit ) {
- $combinations[] = $lowestMultiple + $flipTwo;
- }
- if ( $lowestMultiple + $flipThree <= $limit ) {
- $combinations[] = $lowestMultiple + $flipThree;
- }
- $count++;
- }
- sort( $combinations );
- echo implode( "\n", array_unique( $combinations ) );
- }
- }
- Problem::combination( 10, 15, 55 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement