Skip to content

Instantly share code, notes, and snippets.

@hackur
Last active June 15, 2019 18:36
Show Gist options
  • Save hackur/b24e3e4ff65a447859339a1c38b8ab42 to your computer and use it in GitHub Desktop.
Save hackur/b24e3e4ff65a447859339a1c38b8ab42 to your computer and use it in GitHub Desktop.
VehicleHistory.com - Online Assessment - Question #3
<?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