<html>
<head>
<meta charset="utf-8"/>
<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; }
td { height: 20%; }
</style>
<script type='text/javascript'>
var rldone='';
var first=0;
var altc='';
var supsubmoden=0;
var supsubmodes=['supsub', 'boring', 'sup', 'sub', 'ib', 'bi', 'emoji', 'roman', 'egyptian', 'hexadecimal'];
var curmode=supsubmodes[supsubmoden];
var acontou=null, acontol=null;
var lastprime=-1, prevnum=-1;
var lastfactorslist=[], prevfactorslist=[];
var usuffix='';
var datblock='';
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=[];
var myd = location.search.split('display=')[1] ? dmwork(decodeURIComponent(location.search.split('display=')[1].split('&')[0])) : '';
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') {
if (1 == 1) {
document.getElementById('mytable').innerHTML='';
mynum=eval('' + nn);
altc=document.URL.split('#')[0].split('?')[0] + '?number=' + nn.split('.')[0] + usuffix;
fcalc();
} else {
location.href=document.URL.split('#')[0].split('?')[0] + '?number=' + nn.split('.')[0] + usuffix;
}
}
}
}
function gogethelp() {
window.open('//www.dummies.com/education/math/pre-algebra/10-alternative-numeral-and-number-systems/','_blank','top=20,left=20,width=500,height=500');
}
function egyptian(num) { // thanks to https://www.dummies.com/education/math/pre-algebra/10-alternative-numeral-and-number-systems/
var ems=['🥴','🍳','➰','🧘','🖕','🐸','🤷'];
var descs=['Stroke','Yoke','Coil of rope','Lotus','Finger','Frog','Man with raised hands'];
var retv='';
var cnum='' + num;
var thisc='';
var jnum=0, knum=0;
var iems=eval(-1 + ems.length);
var kiems=0;
while (cnum != '' && iems >= 0) {
if (iems == 0) {
thisc=cnum; //.slice(-1);
cnum='';
jnum=eval('' + thisc);
} else {
thisc=cnum.slice(-1);
cnum=cnum.substring(0, eval(-1 + cnum.length));
jnum=eval('' + thisc);
}
for (knum=0; knum<jnum; knum++) {
retv='<span ' + datblock + 'title="' + descs[kiems] + '" ' + datblock + 'onclick="gogethelp();">' + ems[kiems] + '</span>' + retv;
datblock='';
}
iems--;
kiems++;
}
return retv;
}
function romanize(num) { // thanks to https://stackoverflow.com/questions/9083037/convert-a-number-into-a-roman-numeral-in-javascript/9083076
if (isNaN(num))
return NaN;
var digits = String(+num).split(""),
key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
"","I","II","III","IV","V","VI","VII","VIII","IX"],
roman = "",
i = 3;
while (i--)
roman = (key[+digits.pop() + (i * 10)] || "") + roman;
return Array(+digits.join("") + 1).join("M") + roman;
}
function numer(inn) {
if (supsubmoden == 0 || supsubmoden == 2) {
return '<sup>' + inn + '</sup>';
} else if (supsubmoden == 4) {
return '<i>' + inn + '</i>';
} else if (supsubmoden == 5) {
return '<b>' + inn + '</b>';
} else if (supsubmoden == 6) {
var retv='<sup style="color:purple;background-color:yellow;">'; // 1 ⃣
for (var jj=0; jj<('' + inn).length; jj++) {
retv+='' + ('' + inn).substring(jj, eval(1 + jj)) + ';⃣';
}
return retv + '</sup>';
} else if (supsubmoden == 7) {
return '<sup>' + romanize('' + inn) + '</sup>';
} else if (supsubmoden == 8) {
datblock='data-';
return '<sup>' + egyptian('' + inn) + '</sup>';
} else if (supsubmoden == 9) {
return '<sup>' + eval('' + inn).toString(16) + '</sup>';
}
return '' + inn;
}
function denom(ind) {
if (supsubmoden == 0 || supsubmoden == 3) {
return '<sub>' + ind + '</sub>';
} else if (supsubmoden == 5) {
return '<i>' + ind + '</i>';
} else if (supsubmoden == 4) {
return '<b>' + ind + '</b>';
} else if (supsubmoden == 6) {
var retv='<sub style="color:purple;background-color:yellow;">'; // 1 ⃣
for (var jj=0; jj<('' + ind).length; jj++) {
retv+='' + ('' + ind).substring(jj, eval(1 + jj)) + ';⃣';
}
return retv + '</sub>';
} else if (supsubmoden == 7) {
return '<sub>' + romanize('' + ind) + '</sub>';
} else if (supsubmoden == 8) {
return '<sub>' + egyptian('' + ind) + '</sub>';
} else if (supsubmoden == 9) {
return '<sub>' + eval('' + ind).toString(16) + '</sub>';
}
return '' + ind;
}
function dmwork(huhm) {
huhm=huhm.toLowerCase();
for (var ii=0; ii<supsubmodes.length; ii++) {
if (huhm == supsubmodes[ii]) { usuffix='&display=' + encodeURIComponent(huhm); supsubmoden=ii; curmode=supsubmodes[supsubmoden]; document.getElementById('mytable').innerHTML=''; fcalc(); }
}
}
function displaymode() {
var huhm=prompt("Please choose one of following fraction display options ... supsub, boring, sup, sub, ib, bi, emoji, roman, egyptian, hexadecimal ... for, respectively, sup numerator and sub denominator, no sup nor sub nor i nor b, sup numerator only, sub denominator only, italic numerator and bold denominator, bold numerator and italic denominator, emoji, roman numerals, egyptian, hexadecimal", curmode);
if (huhm == null) { huhm=''; } else { huhm=huhm.toLowerCase(); }
if (1 == 1) {
dmwork(huhm);
} else {
for (var ii=0; ii<supsubmodes.length; ii++) {
if (huhm == supsubmodes[ii]) { supsubmoden=ii; curmode=supsubmodes[supsubmoden]; document.getElementById('mytable').innerHTML=''; fcalc(); }
}
}
}
function fcalc() {
var evens=[' and is even', ' and is odd'];
var sextras=' style="cursor:pointer;" onclick="displaymode();" title="Choose a fractional display mode from supsub, boring, sup, sub, ib, bi, emoji, roman, egyptian, hexadecimal"';
var assessment=' is a prime number' + evens[eval(mynum % 2)] + '.';
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 comaybe=true;
var huhti=1, rect=null, lastrect=null;
divisors=[];
diffs=[];
usuffix='';
datblock='';
prevfactorslist=lastfactorslist;
lastfactorslist=[];
if (prevfactorslist.length == 0 || mynum == prevnum) { comaybe=false; }
for (var ii=mynum; ii>=1; ii--) {
if (('' + eval(mynum / ii)).indexOf('.') == -1) {
divisors.push(ii);
if (eval('' + divisors.length) > 2) { assessment=' is a composite number (ie. not prime)' + evens[eval(mynum % 2)] + '.'; }
facline=facline.replace('</tr>', '<td><span' + sextras + ' class="numerator">' + numer(1) + '</span>/<span class="denominator">' + denom(ii) + '</span></td></tr>');
sextras='';
if (ii != 1 && ii != mynum) { lastfactorslist.push(eval(mynum / ii)); if (prevfactorslist.indexOf(eval(mynum / ii)) != -1) { comaybe=false; } }
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);
}
}
}
if (comaybe) {
assessment+=' The previous number ' + prevnum + ' and this number ' + mynum + ' are <a target=_blank href=https://www.math-only-math.com/various-types-of-numbers.html>co-prime numbers</a>. ';
}
//alert('0:' + altc);
//alert('1:' + assessment);
if (assessment.indexOf(' is a' + ' prime number') != -1 && document.URL.indexOf('&end=') == -1) {
document.getElementById('iupper').src='./fractional_prime.html?number=' + eval(2 + eval('' + mynum)) + '&end=y';
if (eval(-2 + eval('' + mynum)) >= 1) { document.getElementById('ilower').src='./fractional_prime.html?number=' + eval(-2 + eval('' + mynum)) + '&end=y'; }
//alert('2:' + assessment);
} else if (assessment.indexOf(' <a ') == -1) {
//alert('3:' + assessment);
if (altc != '') {
//alert('4:' + assessment);
top.location.href=altc;
}
}
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++;
}
prevnum=mynum;
}
function fupper(iois) {
if (first >= 2) {
acontou = (iois.contentWindow || iois.contentDocument);
if (acontou != null) {
if (acontou.document) { acontou = acontou.document; }
if (acontou.body != null) {
if (acontou.body.innerHTML.indexOf(' is a ' + 'prim' + 'e ') != -1) {
document.getElementById('shuh').innerHTML+=' It has a <a target=_blank href=https://www.math-only-math.com/various-types-of-numbers.html>twin prime number</a> ' + decodeURIComponent(iois.src.split('number=')[1].split('&')[0].split('#')[0]).split('.')[0] + '. ';
}
}
}
}
first++;
if (first == 4) {
first=2;
if (altc != '' && document.getElementById('shuh').innerHTML.indexOf(' <a ') == -1) {
top.location.href=altc;
}
}
}
function flower(iois) {
if (first >= 2) {
acontoi = (iois.contentWindow || iois.contentDocument);
if (acontoi != null) {
if (acontoi.document) { acontoi = acontoi.document; }
if (acontoi.body != null) {
if (acontoi.body.innerHTML.indexOf(' is a ' + 'prim' + 'e ') != -1) {
document.getElementById('shuh').innerHTML+=' It has a <a target=_blank href=https://www.math-only-math.com/various-types-of-numbers.html>twin prime number</a> ' + decodeURIComponent(iois.src.split('number=')[1].split('&')[0].split('#')[0]).split('.')[0] + '. ';
}
}
}
}
first++;
if (first == 4) {
first=2;
if (altc != '' && document.getElementById('shuh').innerHTML.indexOf(' <a ') == -1) {
top.location.href=altc;
}
}
}
function arsthen() {
if (document.getElementById('myicon')) {
document.getElementById('myicon').href='/favicon' + rldone + '.ico';
if (rldone == '') {
rldone='-2';
} else {
rldone='' + eval(-1 + eval('' + rldone));
if (rldone == '-7') { rldone=''; }
}
} else {
var fi=document.createElement('link');
fi.rel='icon';
fi.id='myicon';
if (rldone == '') {
fi.href='/favicon' + rldone + '.ico';
rldone='-2';
} else {
fi.href='/favicon' + rldone + '.ico';
rldone='' + eval(-1 + eval('' + rldone));
if (rldone == '-7') { rldone=''; }
}
document.head.appendChild(fi);
}
setTimeout(arsthen, 1000);
}
setTimeout(arsthen, 1000);
</script>
<!--link rel="shortcut icon" href="/favicon.ico"-->
</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:96%;text-align:center;height:80vh;'>
</table>
<iframe id=iupper style='display:none;' onload='fupper(this);' src='./fractional_prime.html'></iframe>
<iframe id=ilower style='display:none;' onload='flower(this);' src='./fractional_prime.html'></iframe>
</body>
</html>