<html>
<head>
<title>Fractional Approach to Prime Number Detection - RJM Programming - August, 2021</title>
<style>
#tr1 { background-color: lightgreen; }
#tr2 { background-color: lightblue; }
#tr3 { background-color: yellow; }
#tr4 { background-color: pink; }
</style>
<script type='text/javascript'>
var mynum = location.search.split('number=')[1] ? Math.floor(Math.abs(eval(location.search.split('number=')[1].split('&')[0]))) : 60;
var divisors=[]; //, myum];
var diffs=[];
function ask() {
var nn=prompt('Which counting integer are you interested in?', '' + mynum);
if (nn == null) { nn=''; }
if (nn != '') {
if (nn.substring(0,1) >= '1' && nn.substring(0,1) <= '9') {
location.href=document.URL.split('#')[0].split('?')[0] + '?number=' + nn.split('.')[0];
}
}
}
function fcalc() {
var assessment=' is a prime number.';
var innards='', facline='<tr id=tr2></tr>', divline='<tr id=tr3></tr>', diffsline='<tr id=tr4><td colspan=' + divisors.length + '><table style="width:100%;text-align:center;" border=1><tr><td id=td0></td></TR></table></td></tr>';
var lastii=-1;
var huhti=1, rect=null, lastrect=null;
for (var ii=mynum; ii>=1; ii--) {
if (('' + eval(mynum / ii)).indexOf('.') == -1) {
divisors.push(ii);
if (eval('' + divisors.length) > 2) { assessment=' is not a prime number.'; }
facline=facline.replace('</tr>', '<td>1/' + ii + '</td></tr>');
divline=divline.replace('</tr>', '<td id=dt' + divisors.length + '>' + eval(mynum / ii) + '</td></tr>');
if (('' + lastii).indexOf('-') != -1) {
lastii=eval(mynum / ii);
} else {
diffs.push(eval(eval(mynum / ii) - lastii));
diffsline=diffsline.replace('</TR>', '<td id=td' + diffs.length + '>' + eval(eval(mynum / ii) - lastii) + '</td></TR>');
lastii=eval(mynum / ii);
}
}
}
innards+='<tr id=tr1><td colspan=' + divisors.length + '><a onclick=ask(); style="cursor:pointer;text-decoration:underline;">' + mynum + '</a><span id=shuh>' + assessment + '</span></td></tr>' + facline + divline + diffsline.replace(' colspan=0', ' colspan=' + divisors.length).replace('</TR>','<td id=xxx></td></tr>');
document.getElementById('mytable').innerHTML=innards;
while (document.getElementById('dt' + huhti)) {
rect=document.getElementById('dt' + huhti).getBoundingClientRect();
if (huhti == 1) {
document.getElementById('td0').style.width='' + eval(eval('' + rect.width) / 2) + 'px';
document.getElementById('xxx').style.width='' + eval(eval('' + rect.width) / 2) + 'px';
}
if (document.getElementById('dt' + eval(1 + huhti))) {
if (lastrect) {
//alert( eval(eval(eval('' + rect.x) - eval('' + lastrect.x)) / 2));
//document.getElementById('td' + huhti).style.left='' + eval(eval(eval('' + rect.left) - eval('' + lastrect.left)) / 2) + 'px';
document.getElementById('td' + huhti).style.width='' + lastrect.width + 'px';
} else {
document.getElementById('td' + huhti).style.width='' + rect.width + 'px';
}
}
lastrect=rect;
huhti++;
}
}
</script>
</head>
<body onload='fcalc();'>
<h1>Fractional Approach to Prime Number Detection</h1>
<h3>RJM Programming - August, 2021</h3>
<table id=mytable border=1 style='width:100%;text-align:center;'>
</table>
</body>
</html>