Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,50 @@
window.onload = function(){
var list = [];
var j = 0;
for(var c = 1; c <= 200; c++)
for(var b = 1; b <= c; b++)
for(var a = 1; a <= b; a++)
if(gcd(gcd(a, b), c) == 1 && isHeron(heronArea(a, b, c)))
list[j++] = new Array(a, b, c, a + b + c, heronArea(a, b, c));
sort(list);
document.write("<h2>Primitive Heronian triangles with sides up to 200: " + list.length + "</h2><h3>First ten when ordered by increasing area, then perimeter:</h3><table><tr><th>Sides</th><th>Perimeter</th><th>Area</th><tr>");
for(var i = 0; i < 10; i++)
document.write("<tr><td>" + list[i][0] + " x " + list[i][1] + " x " + list[i][2] + "</td><td>" + list[i][3] + "</td><td>" + list[i][4] + "</td></tr>");
document.write("</table><h3>Area = 210</h3><table><tr><th>Sides</th><th>Perimeter</th><th>Area</th><tr>");
for(var i = 0; i < list.length; i++)
if(list[i][4] == 210)
document.write("<tr><td>" + list[i][0] + " x " + list[i][1] + " x " + list[i][2] + "</td><td>" + list[i][3] + "</td><td>" + list[i][4] + "</td></tr>");
function heronArea(a, b, c){
var s = (a + b + c)/ 2;
return Math.sqrt(s *(s -a)*(s - b)*(s - c));
}
function isHeron(h){
return h % 1 == 0 && h > 0;
}
function gcd(a, b){
var leftover = 1, dividend = a > b ? a : b, divisor = a > b ? b : a;
while(leftover != 0){
leftover = dividend % divisor;
if(leftover > 0){
dividend = divisor;
divisor = leftover;
}
}
return divisor;
}
function sort(list){
var swapped = true;
var temp = [];
while(swapped){
swapped = false;
for(var i = 1; i < list.length; i++){
if(list[i][4] < list[i - 1][4] || list[i][4] == list[i - 1][4] && list[i][3] < list[i - 1][3]){
temp = list[i];
list[i] = list[i - 1];
list[i - 1] = temp;
swapped = true;
}
}
}
}
}

View file

@ -0,0 +1,82 @@
(function (n) {
var chain = function (xs, f) { // Monadic bind/chain
return [].concat.apply([], xs.map(f));
},
hArea = function (x, y, z) {
var s = (x + y + z) / 2,
a = s * (s - x) * (s - y) * (s - z);
return a ? Math.sqrt(a) : 0;
},
gcd = function (m, n) { return n ? gcd(n, m % n) : m; },
rng = function (m, n) {
return Array.apply(null, Array(n - m + 1)).map(function (x, i) {
return m + i;
});
},
sum = function (a, x) { return a + x; };
// DEFINING THE SORTED SUB-SET IN TERMS OF A LIST MONAD
var lstHeron = chain( rng(1, n), function (x) {
return chain( rng(x, n), function (y) {
return chain( rng(y, n), function (z) {
return (
(x + y > z) &&
gcd(gcd(x, y), z) === 1 && // Primitive.
(function () { // Heronian.
var a = hArea(x, y, z);
return a && (a === parseInt(a, 10))
})()
) ? [[x, y, z]] : []; // Monadic inject or fail
})})}).sort(function (a, b) {
var dArea = hArea.apply(null, a) - hArea.apply(null, b);
if (dArea) return dArea;
else {
var dPerim = a.reduce(sum, 0) - b.reduce(sum, 0);
return dPerim ? dPerim : (a[2] - b[2]);
}
});
// OUPUT FORMATTED AS TWO WIKITABLES
var lstColumns = ['Sides Perimeter Area'.split(' ')],
fnData = function (lst) {
return [JSON.stringify(lst), lst.reduce(sum, 0), hArea.apply(null, lst)];
},
wikiTable = function (lstRows, blnHeaderRow, strStyle) {
return '{| class="wikitable" ' + (
strStyle ? 'style="' + strStyle + '"' : ''
) + lstRows.map(function (lstRow, iRow) {
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
return typeof v === 'undefined' ? ' ' : v;
}).join(' ' + strDelim + strDelim + ' ');
}).join('') + '\n|}';
};
return 'Found: ' + lstHeron.length +
' primitive Heronian triangles with sides up to ' + n + '.\n\n' +
'(Showing first 10, sorted by increasing area, ' +
'perimeter, and longest side)\n\n' +
wikiTable(
lstColumns.concat(lstHeron.slice(0, 10).map(fnData)),
true
) + '\n\n' +
'All primitive Heronian triangles in this range where area = 210\n' +
'\n(also in order of increasing perimeter and longest side)\n\n' +
wikiTable(
lstColumns.concat(lstHeron.filter(function (x) {
return 210 === hArea.apply(null, x);
}).map(fnData)),
true
) + '\n\n';
})(200);