<?php
$hotels = [
['Cala', 3, 8.7, 6000],
['Ocean', 3, 8.2, 6150],
['Orchid', 3, 8.0, 7200],
['Ya', 3, 8.7, 6950],
['Chaba', 3, 8.2, 7120],
];
var_dump($hotels);
$totalHotelsNumber = 2;
$starCoef = 0.2;
$ratingCoef = 2000;
for ( $i=0; $i<count($hotels); $i++ ) {
$hotels[4] = 0;
}
for ( $i=0; $i<count($hotels); $i++ ) {
for ( $j=$i+1; $j<count($hotels); $j++ ) {
echo $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];
$priceToCompensate = $ratingDifference*$ratingCoef;
$price = $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.57 ms | 402 KiB | 5 Q