#!/usr/local/bin/perl -w for (1..100){ $X[$_]=rand(20)-10; $Y[$_]=rand(20)-10; $Z[$_]=rand(20)-10; $CX += $X[$_]/100; $CY += $Y[$_]/100; $CZ += $Z[$_]/100; } # goto PAR; $rmin = 9e99; for (;;){ $rmax=0; for (1..100){ $r = ($X[$_]-$CX)**2+ ($Y[$_]-$CY)**2 + ($Z[$_]-$CZ)**2; if ($r > $rmax) { $rmax = $r; } } if ($rmax < $rmin){ $rmin = $rmax; $CXopt = $CX; $CYopt = $CY; $CZopt = $CZ; print "$CX $CY $CZ ->",sqrt($rmin),"\n"; } if ($j%9<=2){ $CX = $CXopt + (rand() -0.5)/100; }elsif ($j%9<=5){ $CY = $CYopt + (rand() -0.5)/100; }elsif ($j%9<=8){ $CZ = $CZopt + (rand() -0.5)/100; } $j++; last if ($j==100000); } PAR:; print "Método pares\n"; for $i (1..100){ for $j ($i+1..100){ $CX=($X[$i]+$X[$j])/2; $CY=($Y[$i]+$Y[$j])/2; $CZ=($Z[$i]+$Z[$j])/2; $r = sqrt( ($X[$i]-$X[$j])**2+ ($Y[$i]-$Y[$j])**2+ ($Z[$i]-$Z[$j])**2 )/2; $ok=0; for $k (1..100){ if ( ($X[$k]-$CX)**2+ ($Y[$k]-$CY)**2+ ($Z[$k]-$CZ)**2 > $r*$r) { last; } else { $ok++; }; } if ($ok ==100){ print "$CX $CY $CZ ->$r\n"; } } } __END__ 0.371379237534814912 0.879077953011946463 0.339270803193599555 ->14.4491126616506966 0.370240380851789013 0.88134657266184604 0.335706815553010216 ->14.4491119021293488 0.372694921774303118 0.882884290376678962 0.336687759854835598 ->14.4491116165292598 0.37470123438239952 0.883500720554348149 0.338155553451314575 ->14.4491114663380532 Método pares 0.373993515181538783 0.883581215446014312 0.337327176804436135 ->14.4491110618910625 0.11947665277913412 1.32875450721176485 0.520078271869495872 ->14.5002591879972748 0.119445145922678755 1.33333827539802538 0.524439022942154942 ->14.5002559787044908 0.123081402145552907 1.33294333617757474 0.527721122201496122 ->14.50025413629769 0.118418928404085299 1.33403341041751308 0.52404092279850385 ->14.5002537432193673 0.11778983381488036 1.3356817062322332 0.525000833765011734 ->14.5002503899501131 0.119566983075447055 1.33572014078993536 0.526831022108482223 ->14.5002473397057879 0.119997881933421091 1.33893494223835045 0.530346661946859825 ->14.5002472304729671 0.115009920227319497 1.34109751186670714 0.527363647954514221 ->14.5002431188014678 0.114595877696507386 1.34312633504910394 0.528885662050009522 ->14.5002422245618247 Método pares 0.113322962909165881 1.34437248232678996 0.528789530638675842 ->14.500241941510288