Last active
June 15, 2019 18:36
-
-
Save hackur/b24e3e4ff65a447859339a1c38b8ab42 to your computer and use it in GitHub Desktop.
VehicleHistory.com - Online Assessment - Question #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment