<?php
$hotels = [
['Cala', 3, 8.7, 6000],
['Ocean', 3, 8.2, 6150],
['Orchid', 3, 8.0, 7200],
['Ya', 4, 8.3, 6950],
['Chaba', 3, 8.2, 7120],
];
$top = [
'Ya',
'Ocean',
'Cala',
];
for ( $i=0; $i<count($hotels); $i++ ) {
$hotels[$i][4] = 0;
}
$starCoefOptions = range(0.02, 5, 0.02);
$ratingCoefOptions = range(50, 10000, 50);
foreach ( $starCoefOptions as $starCoef ) {
foreach ( $ratingCoefOptions as $ratingCoef ) {
$topGenerated = buildTop($hotels, $starCoef, $ratingCoef);
$topGenerated = array_slice($topGenerated, 0, count($top));
if ( $topGenerated === $top ) {
echo '$starCoef = '.$starCoef."\r\n";
echo '$ratingCoef = '.$ratingCoef."\r\n";
echo "\r\n";
}
}
}
function buildTop($hotels, $starCoef, $ratingCoef)
{
for ( $i=0; $i<count($hotels); $i++ ) {
for ( $j=$i+1; $j<count($hotels); $j++ ) {
$starDifference = $hotels[$i][1]-$hotels[$j][1];
$ratingToCompensate = $starDifference*$starCoef;
$rating = $hotels[$i][2]+$ratingToCompensate;
$ratingDifference = ($rating-$hotels[$j][2])*10;
$priceToCompensate = $ratingDifference*$ratingCoef;
$price = round($hotels[$i][3]-$priceToCompensate);
if ( $price < $hotels[$j][3] ) {
$hotels[$i][4]++;
} else {
$hotels[$j][4]++;
}
}
}
usort($hotels, function($hotelA, $hotelB){
return $hotelB[4]-$hotelA[4];
});
return array_map(function($hotel){
return $hotel[0];
}, $hotels);
}
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.30, 7.0.0 - 7.0.20, 7.1.0 - 7.1.6, 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.3 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected '[' in /in/r1Ofu on line 3
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected '[' in /in/r1Ofu on line 3
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/r1Ofu on line 3
Process exited with code 255.
preferences:
200.3 ms | 401 KiB | 365 Q