<?php
echo "<b>Условия:</b></br>
<li>Есть 12 шаров, 11 одинаковых, 12-й либо тяжелее, либо легче (это неизвестно).
<li>Есть весы, которые бывают в 3-х положениях ''больше'', ''меньше'' и ''поровну''.
<li>Есть 3 взвешивания, которые можно сделать.</br></br>Необходимо определить какой из шаров имеет аномальную массу. ";
$p = array();
for ($i=0;$i < 12;$i++){
$p[$i+1]=1;
}
$p[9] = 2;
$firstGroup = $p[1]+$p[2]+$p[3]+$p[4];
$secondGroup = $p[5]+$p[6]+$p[7]+$p[8];
$thirdGroup = $p[9]+$p[10]+$p[11]+$p[12];
if($firstGroup == $secondGroup){
if(($p[9]+$p[10]+$p[6]) == ($p[7]+$p[8]+$p[11])){
if($p[9] > $p[12]){
echo('p[12] the smallest ball in comparison with each of the other');
}else if($p[9] < $p[12]){
echo('p[12] biggest ball compared to each of the other');
}
}else if(($p[9]+$p[10]+$p[6]) > ($p[7]+$p[8]+$p[11])){
if($p[9] == $p[10]){
echo('p[11] the smallest ball in comparison with each of the other');
}else if($p[9] > $p[10]){
echo('p[9] biggest ball compared to each of the other');
}else if($p[9] < $p[10]){
echo('p[10] biggest ball compared to each of the other');
}
}else if(($p[9]+$p[10]+$p[6]) < ($p[7]+$p[8]+$p[11])){
if($p[9] == $p[10]){
echo('p[11] biggest ball compared to each of the other');
}else if($p[9] > $p[10]){
echo('p[10] the smallest ball in comparison with each of the other');
}else if($p[9] < $p[10]){
echo('p[9] the smallest ball in comparison with each of the other');
}
}
}else if($firstGroup < $secondGroup){
if(($p[1]+$p[2]+$p[6])==($p[3]+$p[5]+$p[12])){
if($p[7]==$p[8]){
echo('p[4] the smallest ball in comparison with each of the other');
}else if($p[7] < $p[8]){
echo('p[8] biggest ball compared to each of the other');
}else if($p[7] > $p[8]){
echo('p[7] biggest ball compared to each of the other');
}
}else if(($p[1]+$p[2]+$p[6]) < ($p[3]+$p[5]+$p[12])){
if($p[1] == $p[2]){
echo('p[5] biggest ball compared to each of the other');
}else if($p[1] > $p[2]){
echo('p[2] the smallest ball in comparison with each of the other');
}else if($p[1] < $p[2]){
echo('p[1] the smallest ball in comparison with each of the other');
}
}else if(($p[1]+$p[2]+$p[6]) > ($p[3]+$p[5]+$p[12])){
if($p[2]>$p[3]){
echo('p[3] the smallest ball in comparison with each of the other');
}else if($p[2]==$p[3]){
echo('p[6] biggest ball compared to each of the other');
}
}
}else if(firstGroup > secondGroup){
if(($p[5]+$p[6]+$p[2])==($p[7]+$p[1]+$p[12])){
if($p[3]==$p[4]){
echo('p[8] the smallest ball in comparison with each of the other');
}else if($p[3] < $p[4]){
echo('p[4] biggest ball compared to each of the other');
}else if($p[3] > $p[4]){
echo('p[3] biggest ball compared to each of the other');
}
}else if(($p[5]+$p[6]+$p[2]) < ($p[7]+$p[1]+$p[12])){
if($p[5] == $p[6]){
echo('p[1] biggest ball compared to each of the other');
}else if($p[5] > $p[6]){
echo('p[6] the smallest ball in comparison with each of the other');
}else if($p[5] < $p[6]){
echo('p[5] the smallest ball in comparison with each of the other');
}
}else if(($p[5]+$p[6]+$p[2]) > ($p[7]+$p[1]+$p[12])){
if($p[6]>$p[7]){
echo('p[7] the smallest ball in comparison with each of the other');
}else if($p[6]==$p[7]){
echo('p[2] biggest ball compared to each of the other');
}
}
}
?>