<?php
$hotels = [
['Aloft', 4, 8.3, 24756],
['The bestian', 5, 8.0, 26553],
['The royal', 5, 8.2, 32226],
['Royal cariben', 5, 8.3, 33886],
['Kristal', 4, 8.1, 35551],
['Fiesta', 5, 8.2, 38221],
['Presidenta', 5, 8.3, 38500],
['The lagun amar', 5, 8.8, 41454],
['Casa Maya', 5, 8.1, 46518],
['Casa Magna', 4, 8.8, 47408],
['Americana', 5, 9.2, 59580],
];
$totalHotelsNumber = 2;
$starCoef = 0.2;
$ratingCoef = 2000;
for ( $i=0; $i<count($hotels); $i++ ) {
$hotels[$i][4] = 0;
}
for ( $i=0; $i<count($hotels); $i++ ) {
for ( $j=$i+1; $j<count($hotels); $j++ ) {
echo 'Comparing '.$hotels[$i][0].' and '.$hotels[$j][0].'...'."\r\n";
$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);
echo $price.' VS '.$hotels[$j][3]."\r\n";
if ( $price < $hotels[$j][3] ) {
echo $hotels[$i][0].' wins!'."\r\n";
$hotels[$i][4]++;
} else {
echo $hotels[$j][0].' wins!'."\r\n";
$hotels[$j][4]++;
}
echo "\r\n".'----------'."\r\n";
}
}
usort($hotels, function($hotelA, $hotelB){
return $hotelB[4]-$hotelA[4];
});
echo "\r\n".'----------'."\r\n";
echo 'Top:'."\r\n\r\n";
for ( $i=0; $i<count($hotels); $i++ ) {
echo $hotels[$i][0].': '.$hotels[$i][4]."\r\n";
}
echo "\r\n".'----------'."\r\n";
echo 'Finalists:'."\r\n\r\n";
for ( $i=0; $i<=1; $i++ ) {
echo $hotels[$i][0]."\r\n";
}
preferences:
41.37 ms | 402 KiB | 5 Q