LOL! have you ever used this approach to "defeat rounding error"?
You might find you need unbounded length (infinitely big) integer
coefficients for rationals to be more precise than rounded reals.
Mike's solutions are all wrong anyway, his next closest point is not closest
at all as I explained.
He basically travels along the hypotenuse ignoring the 2 closer side points,
but he ignored me pointing this out so his solutions are still way too
large.
I added a temperature to the annealing javascript program. But I didn't
finish the outer loop to test all starting points, Point 1, as I suspect
solutions over 15 points would take a chunk of computer time in a compiled
language.
NEW VERSION
http://freewebs.com/namesort/matheology/LONGEST-WALK-CENTER.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<TITLE>Longest Walk Inside a Unit Square</TITLE>
</HEAD>
<BODY bgcolor="#000000" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF">
<b>LENGTH: </b><b id="lenseg"></b><br>
<b>POINTS: </b>
<select onchange="points = this.options[this.selectedIndex].value;init()">
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
<option value=12>12</option>
<option value=16>16</option>
<option value=20>20</option>
<option value=25>25</option>
<option value=30>30</option>
<option value=40>40</option>
<option value=50>50</option>
<option value=75>75</option>
<option value=100>100</option>
</select>
<br>
<b>TEMP: </b>
<select onchange="temp = this.options[this.selectedIndex].value;">
<option value=100000>1000</option>
<option value=100 selected=true>100</option>
<option value=20>20</option>
<option value=10>10</option>
<option value=5>5</option>
<option value=2>2</option>
<option value=1>1</option>
<option value=0>0</option>
</select>
<SCRIPT LANGUAGE="JavaScript">
if (document.getElementById){
// Plenty of black gives a better sparkle effect.
showerCol=new
Array('#000000','#ff0000','#ffffff','#000000','#00ff00','#ff00ff','#ffffff','#ffa500','#000000','#fff000');
launchCol=new Array('#ffff00','#ff00ff','#00ffff','#ffffff','#ff8000');
runSpeed=10; //setTimeout speed.
// *** DO NOT EDIT BELOW ***
steps = 1000
points = 101
spiralx=new Array()
spiraly=new Array()
newx = new Array()
newy = new Array()
sortx = new Array()
sorty = new Array()
sorted = new Array()
lengthspiral = 0
temp = 100
var yPos=200;
var xPos=200;
var explosionSize=200;
var launchColour='#ffff80';
var timer=null;
var dims=1;
var evn=360/14;
firework=new Array();
var ieType=(typeof window.innerWidth != 'number');
var ieRef=((ieType) && (document.compatMode) &&
(document.compatMode.indexOf("CSS") != -1))
?document.documentElement:document.body;
thisStep=0;
step=1;
function init() {
for (i=0; i < 101; i++){
spiralx[i] = 0
spiraly[i] = 0
newx[i] = 0
newy[i] = 0
firework[i].top = -100 +"px";
firework[i].left = -100 +"px";
}
lengthspiral = -1
}
for (i=0; i < points; i++){
document.write('<div id="sparks'+i+'"
style="position:absolute;top:0px;left:0px;height:8px;width:8px;font-size:8px;color:#000000;background-color:'+launchColour+'"> <b>'+(i+1)+'</b><\/div>');
firework[i]=document.getElementById("sparks"+i).style;
}
document.write('<div id="topl"
style="position:absolute;top:100px;left:300px;height:1px;width:1px;font-size:1px;color:#000000;background-color:#FFFF00"><\/div>');
document.write('<div id="topr"
style="position:absolute;top:100px;left:507px;height:1px;width:1px;font-size:1px;color:#000000;background-color:#FFFF00"><\/div>');
document.write('<div id="botl"
style="position:absolute;top:309px;left:300px;height:1px;width:1px;font-size:1px;color:#000000;background-color:#FFFF00"><\/div>');
document.write('<div id="botr"
style="position:absolute;top:309px;left:507px;height:1px;width:1px;font-size:1px;color:#000000;background-color:#FFFF00"><\/div>');
function winDims(){
winH=(ieType)?ieRef.clientHeight:window.innerHeight;
winW=(ieType)?ieRef.clientWidth:window.innerWidth;
bestFit=(winW >= winH)?winH:winW;
}
winDims();
window.onresize=new Function("winDims()");
function Fireworks(){
oldl = lengthspiral
lengthspiral = 0
lengthsp = 0
for (i=0; i < points; i++){
newx[i] = spiralx[i] + Math.round(Math.random()*4)-2;
newy[i] = spiraly[i] + Math.round(Math.random()*4)-2;
if (newx[i] > 100) { newx[i] = 100 }
if (newx[i] < -100) { newx[i] = -100 }
if (newy[i] > 100) { newy[i] = 100 }
if (newy[i] < -100) { newy[i] = -100 }
sorted[i] = false
}
nextp = 0
sortx[0] = newx[nextp]
sorty[0] = newy[nextp]
sorted[0] = true
for (i=1; i < points; i++){
curp = nextp
smallest = 10000000
small2 = 1
for (j=1; j < points; j++) {
if (!sorted[j]) {
base = newx[j] - newx[curp]
hite = newy[j] - newy[curp]
lengthseg = Math.pow(base*base + hite*hite, 0.48)
lengthseg2 = Math.pow(base*base + hite*hite, 0.5)
if (lengthseg < smallest) {
smallest = lengthseg
nextp = j
small2 = lengthseg2
}
}
}
sortx[i] = newx[nextp]
sorty[i] = newy[nextp]
sorted[nextp] = true
lengthspiral+= smallest
lengthsp+= small2
}
keep = false
if (lengthspiral > oldl) {
keep = true
document.getElementById("lenseg").innerHTML = parseInt(lengthsp) / 200
lengthspiral = lengthspiral - temp*Math.sqrt(points)/200
}
else {
lengthspiral = oldl - temp*Math.sqrt(points)/200
}
if (keep) {
for (i=0; i < points; i++){
spiralx[i] = sortx[i]
spiraly[i] = sorty[i]
firework[i].top = 200 + spiralx[i] + "px";
firework[i].left = 400 + spiraly[i] +"px";
}
}
thisStep+=step;
timer=setTimeout("Fireworks()",runSpeed);
}
window.onload=doFireworks;
}
function doFireworks(){
init()
points = 2
Fireworks()
}
//-->
</SCRIPT>
</body></HTML>
You just need to add another outer loop to test all starting points instead
of always measuring from Point 1.
That would make it a cubic algorithm per arrangement, which is getting slow
in Javascript!
--
http://MATHEOLOGY.com